1

I am trying to print a json text pretty in the command line,

{"en":"surprise","de":"Überraschung"}

The command python -m json.tool prints it pretty, but with \u...:

$ echo '{"en":"surprise","de":"Überraschung"}' | python -m json.tool
{
    "de": "\u00dcberraschung",
    "en": "surprise"
}

Could you please advise how to solve it in the command line?

Walrus
  • 309
  • 1
  • 3
  • 16
  • 1
    Possible duplicate of [Saving utf-8 texts in json.dumps as UTF8, not as \u escape sequence](https://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence) – tripleee Mar 31 '19 at 11:34
  • Tangentially, also lose the [useless use of `cat`](/questions/11710552/useless-use-of-cat) – tripleee Mar 31 '19 at 11:35
  • [`json.tool`](https://github.com/python/cpython/blob/3.7/Lib/json/tool.py) does not expose an option for this; but requiring a solution which does not involve programming makes your question off-topic for Stack Overflow anyway. – tripleee Mar 31 '19 at 11:38
  • Thank you for hints. I do not insist on this python solution with `json.tool`. It could be another way. Just I am looking for a solution how to print a json output pretty and with normal text. And `cat` is just for example. – Walrus Mar 31 '19 at 11:46

2 Answers2

3

try jq.

echo '{"en":"surprise","de":"Überraschung"}' | jq
{
  "en": "surprise",
  "de": "Überraschung"
}
Dotan
  • 6,602
  • 10
  • 34
  • 47
1

Now we can do it with option --no-ensure-ascii

$ echo '{"en":"surprise","de":"Überraschung"}' | python -m json.tool --no-ensure-ascii
{
    "en": "surprise",
    "de": "Überraschung"
}

tested on python 3.9.9

MocXi
  • 456
  • 5
  • 14