I have problems filtering and updating the content of a json file using jq. I need to filter json data based on specific values, and based on that filter edit other values and increment others
I have tried to use
jq '.[] | select (."name"| contains("CHANNEL1"))'
to filter but the result is missing the top key "x-ID.0" info, the result is the following :
{
"_file.name": "filename.ext",
"name": "CHANNEL1 HD TV",
"logo": "file.png",
"x-channelID": "726"
}
{
"_file.m3u.name": "filename.ext",
"name": "CHANNEL1 SD",
"logo": "file.png",
"x-channelID": "726"
}
For renumbering i have tested the function below and it works well
jq -n -s '[ foreach inputs[] as $i (100; .+1; $i*{"x-channelID":(.-1)}) ]'
Here is the original json file
{
"x-ID.0": {
"_file.name": "filename.ext",
"name": "CHANNEL1 HD TV",
"logo": "file.png",
"x-channelID": "726"
},
"x-ID.2": {
"_file.m3u.name": "filename.ext",
"name": "CHANNEL2",
"logo": "file.png",
"x-channelID": "106"
},
"x-ID.3": {
"_file.m3u.name": "filename.ext",
"name": "CHANNEL3 SD",
"logo": "file.png",
"x-channelID": "236"
},
"x-ID.4": {
"_file.m3u.name": "filename.ext",
"name": "CHANNEL1 SD",
"logo": "file.png",
"x-channelID": "726"
},
"x-ID.5": {
"_file.m3u.name": "filename.ext",
"name": "CHANNEL2 HD",
"logo": "file.png",
"x-channelID": "726"
}
}
here is the expected the result
{
"x-ID.0": {
"_file.m3u.name": "filename.ext",
"name": "CHANNEL1 HD",
"logo": "CHANNEL1.png",
"x-channelID": "100"
},
"x-ID.4": {
"_file.m3u.name": "filename.ext",
"name": "CHANNEL1 SD",
"logo": "CHANNEL1.png",
"x-channelID": "101"
}
}
Thanks for your help !