One procedure in a system is to 'extract' one key and its (object) value to a dedicated file to subsequently process it in some way in a (irrelevant) script.
A representative subset of the original JSON file looks like:
{
"version" : null,
"produced" : "2021-01-01T00:00:00+0000",
"other": "content here",
"items" : [
{
"code" : "AA",
"name" : "Example 1",
"prices" : [ "other", "content", "here" ]
},
{
"code" : "BB",
"name" : "Example 2",
"prices" : [ "other", "content", "here" ]
}
]
}
And the current output, given that subset as input, simply equals:
[
{
"code" : "AA",
"name" : "Example 1",
"prices" : [ "other", "content", "here" ],
},
{
"code" : "BB",
"name" : "Example 2",
"prices" : [ "other", "content", "here" ],
},
...
]
Previously, we would extract the whole portion of "items" using jq with a very straightforward command (which worked fine):
cat file.json | jq '.items' > file.items.json
However, recently the size of the original json file has increased drastically in size, causing the script to fail due to a Out of memory error. One obvious solution is to use jq's 'stream' option. However, I am kind of stuck on how to convert above command to a valid filter in jq's stream syntax.
cat file.json | jq --stream '...' > file.items.json
Any advice on what to use as a filter for this command would be greatly appreciated. Thanks in advance!