Hello all,
I receive such json file as input. As you can see it is an array of objects where each object is an array of sub-objects. Brief it is a collection of nested objects and arrays. I don't know in advance the structure, the name of the keys and the levels of nesting. Or even it can also be the other way around, a collection of objects with arrays nested on it. The only thing I should know is the object identifier "key name" found at level 2 (in my example "Obj11Id", "Obj12Id", etc). My goal is for each pair of key name and value, to have the "full path" of the key name and the key value. By "full path" I understand the name of the above keys in the structure.
Example: for the pair "Obj11AttributesObj1Key1": "1", the "full path" would be: "Obj1.Obj11Attributes.Obj11AttributesObj1.Obj11AttributesObj1Key1" (dot "." being the separator of the above keys).
I'm new in Perl, I've tried many ways to obtain this info but failed. I'm using the library JSON::PP and function decode_json.
Thank you
The input json file:
[ { "Obj1": [ { "Obj11Id": "Id11", "Obj11Version": "v1", "Obj11Attributes": { "Obj11AttributesObj1": { "Obj11AttributesObj1Key1": "1", "Obj11AttributesObj1Key2": "3" }, "Obj11AttributesObj2": { "Obj11AttributesObj2Key1": "9" } } }, { "Obj12Id": "Id12", "Obj12Version": "v1", "Obj12Attributes": { "Obj12AttributesObj1": { "Obj12AttributesObj1Key1": "2", "Obj12AttributesObj1Key2": "4" }, "Obj12AttributesObj2": { "Obj12AttributesObj2Key1": "8" }, "Obj12AttributesArray1": [ { "Obj12AttributesArray1Obj1Key1": 1 } ] } } ] }, { "Obj2": [ { "Obj21Id": "Id21", "Obj21Version": "v1", "Obj21Attributes": { "Obj21AttributesObj1": { "Obj21AttributesObj1Key1": "3", "Obj21AttributesObj1Key2": "5" }, "Obj21AttributesObj2": { "Obj21AttributesObj2Key1": "7" } } }, { "Obj22Id": "Id22", "Obj22Version": "v1", "Obj22Attributes": { "Obj22AttributesObj1": { "Obj22AttributesObj1Key1": "4", "Obj22AttributesObj1Key2": "6" }, "Obj22AttributesObj2": { "Obj22AttributesObj2Key1": "0" }, "Obj22AttributesArray1": [ { "Obj22AttributesArray1Obj1Key1": 1 } ] } } ] } ]
In reply to Obtain the full path of a json key by eny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |