[{"data":1,"prerenderedAt":139},["ShallowReactive",2],{"blog-post-jq-add-key-to-json":3,"recent-posts":76},{"id":4,"uid":5,"url":6,"type":7,"href":8,"tags":9,"first_publication_date":10,"last_publication_date":10,"slugs":11,"linked_documents":13,"lang":14,"alternate_languages":15,"data":16},"awgjCRIAACoAhibw","jq-add-key-to-json",null,"blog_posts","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=axNCmBMAACwA2vJJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22awgjCRIAACoAhibw%22%29+%5D%5D",[],"2026-12-04T22:45:44+0000",[12],"jq-how-to-add-a-key-to-json",[],"en-us",[],{"title":17,"date":23,"description":24,"image":29,"content":39},[18],{"type":19,"text":20,"spans":21,"direction":22},"heading1","jq: How to Add a Key to JSON",[],"ltr","2026-12-04",[25],{"type":26,"text":27,"spans":28,"direction":22},"heading2","Learn how to add a key to a JSON object with jq",[],{"dimensions":30,"alt":20,"copyright":6,"url":33,"id":34,"edit":35},{"width":31,"height":32},1280,720,"https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002FkWsRFPiUvQFe1De7_jq-add-key-to-json.png?auto=format,compress","kWsRFPiUvQFe1De7",{"x":36,"y":36,"zoom":37,"background":38},0,1,"transparent",[40,44,48,51,54,57,60,63,66,69,73],{"type":41,"text":42,"spans":43,"direction":22},"paragraph","Before we start, make sure you have jq installed on your computer. On a Mac, you can install it with Homebrew:",[],{"type":45,"text":46,"spans":47,"direction":22},"preformatted","brew install jq",[],{"type":41,"text":49,"spans":50,"direction":22},"First, open your terminal and navigate to the folder with your JSON file. To add a key, use \u003Ccode>.key = value\u003C\u002Fcode>:",[],{"type":45,"text":52,"spans":53,"direction":22},"jq '.role = \"admin\"' input.json",[],{"type":41,"text":55,"spans":56,"direction":22},"If the key already exists, it gets overwritten. For numbers or booleans, leave out the double quotes, like \u003Ccode>.active = true\u003C\u002Fcode>, and for nested keys just chain them: \u003Ccode>.user.role\u003C\u002Fcode>.",[],{"type":41,"text":58,"spans":59,"direction":22},"To add several keys at once, merge in an object with \u003Ccode>. + {\"role\": \"admin\", \"active\": true}\u003C\u002Fcode>. Put the object on the left, \u003Ccode>{\"role\": \"guest\"} + .\u003C\u002Fcode>, and it works as a default that's only used when the key is missing.",[],{"type":41,"text":61,"spans":62,"direction":22},"To use a shell variable, pass it with \u003Ccode>--arg\u003C\u002Fcode> (or \u003Ccode>--argjson\u003C\u002Fcode> for numbers and booleans) instead of pasting it into the filter. For a list of objects, wrap the assignment in \u003Ccode>map()\u003C\u002Fcode>: \u003Ccode>jq 'map(.active = true)' input.json\u003C\u002Fcode>.",[],{"type":41,"text":64,"spans":65,"direction":22},"jq only prints the result. To save it, write to a temp file and move it back:",[],{"type":45,"text":67,"spans":68,"direction":22},"jq '.role = \"admin\"' input.json > tmp.json && mv tmp.json input.json",[],{"type":70,"oembed":71},"embed",{"embed_url":72,"type":70},"",{"type":41,"text":74,"spans":75,"direction":22},"Never redirect straight into the same file, like \u003Ccode>> input.json\u003C\u002Fcode>. The shell empties it before jq reads it, and you end up with an empty file.",[],{"results":77,"page":37,"results_per_page":137,"results_size":137,"total_results_size":138,"total_pages":37},[78,98,117],{"id":79,"uid":80,"url":6,"type":7,"href":81,"tags":82,"first_publication_date":10,"last_publication_date":10,"slugs":83,"linked_documents":85,"lang":14,"alternate_languages":86,"data":87},"awgi0RIAACYAhiZv","ripgrep-replace-text-in-files","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=axNCmBMAACwA2vJJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22awgi0RIAACYAhiZv%22%29+%5D%5D",[],[84],"how-to-replace-text-in-files-with-ripgrep-and-sed",[],[],{"image":88,"title":94},{"dimensions":89,"alt":90,"copyright":6,"url":91,"id":92,"edit":93},{"width":31,"height":32},"Ripgrep: How to Replace Text in Files with Ripgrep and Sed","https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002FOlJ7le5oNEXxcE_I_ripgrep-replace-text-in-files.png?auto=format,compress","OlJ7le5oNEXxcE_I",{"x":36,"y":36,"zoom":37,"background":38},[95],{"type":19,"text":96,"spans":97,"direction":22},"How to Replace Text in Files with Ripgrep and Sed",[],{"id":99,"uid":100,"url":6,"type":7,"href":101,"tags":102,"first_publication_date":10,"last_publication_date":10,"slugs":103,"linked_documents":105,"lang":14,"alternate_languages":106,"data":107},"awgi2hIAACoAhiaF","ripgrep-case-insensitive-search","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=axNCmBMAACwA2vJJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22awgi2hIAACoAhiaF%22%29+%5D%5D",[],[104],"ripgrep-how-to-search-case-insensitive",[],[],{"image":108,"title":114},{"dimensions":109,"alt":110,"copyright":6,"url":111,"id":112,"edit":113},{"width":31,"height":32},"Ripgrep: How to Search Case Insensitive","https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002F6H2DfjROfkSO4wel_ripgrep-case-insensitive-search.png?auto=format,compress","6H2DfjROfkSO4wel",{"x":36,"y":36,"zoom":37,"background":38},[115],{"type":19,"text":110,"spans":116,"direction":22},[],{"id":118,"uid":119,"url":6,"type":7,"href":120,"tags":121,"first_publication_date":10,"last_publication_date":10,"slugs":122,"linked_documents":124,"lang":14,"alternate_languages":125,"data":126},"awgi_hIAACoAhibc","jq-use-with-curl","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=axNCmBMAACwA2vJJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22awgi_hIAACoAhibc%22%29+%5D%5D",[],[123],"how-to-use-jq-with-curl",[],[],{"image":127,"title":133},{"dimensions":128,"alt":129,"copyright":6,"url":130,"id":131,"edit":132},{"width":31,"height":32},"jq: How to Use jq with curl","https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002F3JyqU0cTsv3S-6D0_jq-use-with-curl.png?auto=format,compress","3JyqU0cTsv3S-6D0",{"x":36,"y":36,"zoom":37,"background":38},[134],{"type":19,"text":135,"spans":136,"direction":22},"How to Use 'jq' with 'curl'",[],3,137,1796424369459]