Table of Contents

Use jq utility to pretty format json

If you get an error like parse error: Invalid numeric literal at line 1, column 7

this is could be because the json contains single quotes instead of double quotes. This is invalid JSON:

{'red': {'hue': {'dark': 2, 'white': 1}}, 'blue': {'blue': {'dark': 3, 'white': 3}, 'blue-2': {'dark': 3, 'white': 3}}}

JSON uses double quotes for strings. Use this to pipe the command to sed. Notice the double quotes around the whole json in echo command (it won't work otherwise):

echo "{'red': {'hue': {'dark': 2, 'white': 1}}, 'blue': {'blue': {'dark': 3, 'white': 3}, 'blue-2': {'dark': 3, 'white': 3}}}" | sed 's/'\''/"/g' | jq .

Output:

{
  "red": {
    "hue": {
      "dark": 2,
      "white": 1
    }
  },
  "blue": {
    "blue": {
      "dark": 3,
      "white": 3
    },
    "blue-2": {
      "dark": 3,
      "white": 3
    }
  }
}

Another problem could be unquoted true or false statements, so quote those instances in the file.

“freeshipping”: false → “freeshipping”: “false”

Tested on

See also

References