Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 644

How to insert JSON into table beside a specific value using JQ

$
0
0

In this JSON snippet

[  {"user":"user-1","videos":[      {"key":"key1","url":"url1"      }    ]  },  {"user":"user-2","videos":[      {"key":"key2","url":"url2"      }    ]  }]

I want to add {"key":"key3","url":"url3"} under videos that is beside "user":"user-2"

ideally it will look like this:

[  {"user":"user-1","videos":[      {"key":"key1","title":"title1"      }    ]  },  {"user":"user-2","videos":[      {"key":"key2","title":"title2"      },      {"key":"key3","title":"title3"      }    ]  }]

I tried

jq '. += [{"user":"user-2","videos":[{"key":"key3","title":"title3"}]}]'

but it adds a whole new user-2


Viewing all articles
Browse latest Browse all 644

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>