Consume Dynamic JSON
Posted: Wed Aug 11, 2021 5:54 pm
I have an old application in which it is receiving multiple JSON with data elements in it . The only common element in all those JSON is a field name "title" which will give some heading and based on that heading we write different subroutine/procedure to extract the data and as it dynamic and fields are different in every JSON i have to hard code the key and then retrieve it's value. I was trying to make it more simpler by using two ways:-
1) Using DATA-INTO and create DS for every JSON and get the data but the issue is some JSON have common field name so i can't declare same field name in multiple DS. and if i change the field name not sure DATA-INTO will work or not? But still i have to declare multiple DS.
2) write a program to get the "KEY" name from JSON and then store it in an Array / temp file and then read that Array/Temp file and get all the values using
In option 2) i can reduce my code by the putting above line in loop and reading it into the loop and storing the data whenever i want..
But i don't know if there is any method to get only KEY names in JSON? other then find it using %SCAN, comma, double quotes ...etc..etc
JSON EXAMPLE:-
Any suggestion to handle such cases\?
1) Using DATA-INTO and create DS for every JSON and get the data but the issue is some JSON have common field name so i can't declare same field name in multiple DS. and if i change the field name not sure DATA-INTO will work or not? But still i have to declare multiple DS.
2) write a program to get the "KEY" name from JSON and then store it in an Array / temp file and then read that Array/Temp file and get all the values using
Code: Select all
YAJL_OBJECT_FIND(<arrayname[index]/temp file field name)
In option 2) i can reduce my code by the putting above line in loop and reading it into the loop and storing the data whenever i want..
But i don't know if there is any method to get only KEY names in JSON? other then find it using %SCAN, comma, double quotes ...etc..etc
JSON EXAMPLE:-
Code: Select all
{"data":{"odom":2023,"tRead":"311","teMde":"PED"
},title-"JSON1"}
{"data":{"om":"208706.05","fix1":"36","lastread":"PRO"
},title-"JSON2"}