Skip to content

jkit format

Pretty-print JSON with 4-space indentation.

bash
jkit format       # full name
jkit f            # short alias

Synopsis

jkit format
jkit f

No arguments. Reads from stdin or the clipboard — see Input handling.

What it does

  • Decodes the input with json.Number so big integers keep their precision.
  • Emits the result with 4-space indentation.

Example

bash
> echo '{"data":{"area":"东京Amazon数据中心","country":"日本","ip":"52.68.96.58"},"error":0,"msg":"success"}' | jkit f

{
    "data": {
        "area": "东京Amazon数据中心",
        "country": "日本",
        "ip": "52.68.96.58"
    },
    "error": 0,
    "msg": "success"
}

Number precision

Most JSON tools quietly destroy 64-bit integers by decoding them through float64. jkit f doesn't:

bash
> echo '{"id":9223372036854775807}' | jkit f

{
    "id": 9223372036854775807
}

Comparison

Without UseNumber, the same input would round-trip to 9.223372036854776e+18 and you'd lose the lowest digits.

Errors

Invalid input fails fast with a parse error and exit code 1:

bash
> echo '{not json' | jkit f
jkit: parse json: invalid character 'n' looking for beginning of object key string