I need to append content in my primary file with information from a secondary file.
The primary file looks like this one:
[ { "dynamic-parent-key-1": { "key1": "value1", "key2": "value2", "array1": [ "array-value-1", "array-value-2" ] } }, { "dynamic-parent-key-2": { "key1": "value1", "key2": "value2", "array1": [ "array-value-1" ] } } ] And the secondary file looks like this one:
{ "fixedKey": [ { "Key": "A", "Value": "abc" }, { "Key": "B", "Value": "xyz" }, { "Key": "C", "Value": "asd" } ] } { "fixedKey": [ { "Key": "A", "Value": "aaa" }, { "Key": "B", "Value": "bbb" }, { "Key": "C", "Value": "ccc" } ] } The elements order is related. The first object "fixedKey" corresponds to "dynamic-parent-key-1" and so on. The first file is JSON compliant and the second is not, it is just a list of JSON objects saved on a common file.
I need an output file (or just update the first one) so it looks ideally like this:
{ "master-key": { "dynamic-parent-key-1": { "key1": "value1", "key2": "value2", "array1": [ "array-value-1", "array-value-2" ], "fixedKey": [ { "Key": "A", "Value": "abc" }, { "Key": "B", "Value": "xyz" }, { "Key": "C", "Value": "asd" } ] }, "dynamic-parent-key-2": { "key1": "value1", "key2": "value2", "array1": [ "array-value-1" ], "fixedKey": [ { "Key": "A", "Value": "aaa" }, { "Key": "B", "Value": "bbb" }, { "Key": "C", "Value": "ccc" } ] } } } But if that is not possible or too complicated, I could stick to first file structure and obtain something like this:
[ { "dynamic-parent-key-1": { "key1": "value1", "key2": "value2", "array1": [ "array-value-1", "array-value-2" ], "fixedKey": [ { "Key": "A", "Value": "abc" }, { "Key": "B", "Value": "xyz" }, { "Key": "C", "Value": "asd" } ] } }, { "dynamic-parent-key-2": { "key1": "value1", "key2": "value2", "array1": [ "array-value-1" ], "fixedKey": [ { "Key": "A", "Value": "aaa" }, { "Key": "B", "Value": "bbb" }, { "Key": "C", "Value": "ccc" } ] } } ] How can I achieve this? I've been trying with map(), |=, + but I can't make it. Should I first prepare my secondary file to be JSON compliant or it is not necessary?