I have json file which will grow in future so i want to split it as parent and child in one folder and refer all child in parent file so i could manage multiple file rather than one big file. I am using this file for configurations
Following is example to demonstrate my requirement
Main.json
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
I want to split like below
Parent.json
{
"store": {
"book": [
"$ref": "book1.json",
"$ref": "book2.json"
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
book1.json
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
}
I tried to display parent file but its giving error, I want that parent.json should display as main.json
# jq . parent.json
parse error: ':' not as part of an object at line 10, column 19
Parent.jsonis invalid JSON -"book": [ ... ]contains records which supposed to be listed in object, i.e.:"book": { ... }"label": "value", only objects do. If you like to list your entries as they spelled (i.e. with labels), then it should be like this"book": [ {"$ref": "book1.json"}, {"$ref": "book2.json"} ]Parent.jsonnot in a JSON compliant format (so it'll be partially compliant), then you cannot use json tools to parse it right (cause the file violates JSON semantic). Thus you have to rely on text based tools (likeawk,sed) to perform required substitution. But then, you'll be exposed to risk of facing false positives/negatives sooner of later (cause those text aware tools do not understand/handle recurrent/nested formats).