LoginSignup
9
6

More than 5 years have passed since last update.

エスケープされた json を jq で整形する

Posted at

どういうことか

こういうエスケープされた json 部分を整形して表示したい

{
  "a" : 1,
  "b" : 2,
  "c" : "{\"id\":\"hoge\",\"parent\":\"abc\"}\n"
}

解決法

fromjson を使う。

$ pbpaste
{
  "a" : 1,
  "b" : 2,
  "c" : "{\"id\":\"hoge\",\"parent\":\"abc\"}\n"
}
$ pbpaste | jq '.c | fromjson'
{
  "id": "hoge",
  "parent": "abc"
}

参考

Use jq to parse a JSON String - Stack Overflow
https://stackoverflow.com/questions/35154684/use-jq-to-parse-a-json-string

jq Manual (development version)
https://stedolan.github.io/jq/manual/

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6