format · validate · convert · runs locally

Parse JSON in Bash

How to parse a JSON string into an object and serialize (stringify) an object back to JSON in Bash. jq is the standard command-line JSON processor; install it from your package manager. Need to clean up the JSON first? Use the formatter & validator.

Parse JSON (string → object)

# jq reads JSON from stdin
id=$(echo "$text" | jq -r '.id')

Stringify (object → JSON string)

# build JSON with jq
text=$(jq -n --arg name "Ann" '{name: $name}')

Frequently asked questions

How do I parse JSON in Bash?

jq is the standard command-line JSON processor; install it from your package manager. Parse with the snippet above; the result is a native object/map you can read.

How do I pretty-print JSON in Bash?

Use the stringify snippet above with indentation, or paste your JSON into the formatter on this page.