I want to encode json/xml payload based on other property/json file.
master file:
{
"keys": {
"Name": "abcd",
"age": "trst",
"USA": "bcd",
"country": "wert"
}
}
Source payload:
{
"Name": "John",
"age": 23,
"Address": {
"state": "Texas",
"country": "USA"
}
}
expected encoded payload:
{
"abcd": "John",
"trst": 23,
"Address": {
"state": "Texas",
"wert": "bcd"
}
}
NOTE: this Source payload can be a xml file if needed. ( if that can provide fast solution than json. in that case expected encoded payload also can be a xml)
I have couple of ideas,
- keep master file in a map and traverse through json object / xml file reading each key and value. while traversing read from map and replace
- consider source payload as string and do string replace using regex. (create dynamic regex using master file like ("Name"|"age"|"USA"|"country") and parse and replace that
Objective is find most accurate and performance wise good solution. appreciate if you can share your ideas and small sample if possible. OR is there any library where we can do this type of things?