[jq] Parse a JSON string with fromjson

Created on November 30, 2026

fromjson reads a string containing valid JSON and returns the corresponding value. This example parses the text stored in payload.

printf '%s\n' '{"id":1,"payload":"{\"name\":\"Taro\",\"score\":80}"}' |
  jq '.payload | fromjson'
{
  "name": "Taro",
  "score": 80
}

The decoded object has name and score fields.

Decode a field in place

With |=, you can replace the field with its decoded value and preserve the other fields.

printf '%s\n' '{"id":1,"payload":"{\"name\":\"Taro\",\"score\":80}"}' |
  jq '.payload |= fromjson'
{
  "id": 1,
  "payload": {
    "name": "Taro",
    "score": 80
  }
}

Invalid JSON in the string produces a parse error.

Reference

jq