Choose one: Hardware, Software, Coding, Game, or Windowsโฑ๏ธ 2 min read๐
2026-06-03
How to Fix: How do I update a single value in a json document using jq?
SEO meta description 140-155 characters.
Quick Answer: 1-2 sentences of direct conversational advice.
๐ Table of Contents
To update a single value in a JSON document using jq, you can use the following command:
๐ Updating a Single Value with jq
- Use the `.[]` syntax to update an array value:
Example 1: Updating a Single Value in an Array
curl http://example.com/shipping.json | jq '.items[] |= . + { field: value }' | curl -X PUT http://example.com/shipping.jsonExample 2: Updating a Single Value in an Object
curl http://example.com/shipping.json | jq '.field = value' | curl -X PUT http://example.com/shipping.json๐ ๏ธ Step-by-Step Verified Fixes
Method 1: [Name]
- Step 1: Use the `.[]` syntax to update an array value.
Method 2: [Name]
- Step 1: Use the `.` syntax to access a nested object.
๐ฏ Final Words
[Wrap-up]
โ Frequently Asked Questions
Use the `.[]` syntax to update an array value:
curl http://example.com/shipping.json | jq '.items[] |= . + { field: value }' | curl -X PUT http://example.com/shipping.jsonExample 2: Updating a Single Value in an Objectcurl http://example.com/shipping.json | jq '.field = value' | curl -X PUT http://example.com/shipping.json๐ ๏ธ Step-by-Step Verifie
Step 1: Use the `.` syntax to access a nested object.