LoginSignup
6

More than 3 years have passed since last update.

posted at

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

どういうことか

こういうエスケープされた 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/

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
What you can do with signing up
6