리눅스 Pretty JSON 출력 (jq 사용)

리눅스 Pretty JSON 출력 (jq)

1 사전 작업[ | ]

2 사용 방법[ | ]

출력명령어 | jq .

3 실습 1[ | ]

[root@zetawiki ~]# echo '{"foo": "lorem", "bar": "ipsum"}'
{"foo": "lorem", "bar": "ipsum"}
[root@zetawiki ~]# echo '{"foo": "lorem", "bar": "ipsum"}' | jq .
{
  "foo": "lorem",
  "bar": "ipsum"
}

4 실습 2[ | ]

[root@zetawiki ~]# curl -s https://api.twitter.com/hello.json
{"errors":[{"message":"Sorry, that page does not exist","code":34}]}
[root@zetawiki ~]# curl -s https://api.twitter.com/hello.json | jq .
{
  "errors": [
    {
      "message": "Sorry, that page does not exist",
      "code": 34
    }
  ]
}

5 실습 3[ | ]

[root@zetawiki ~]# curl -s 'https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info&pageids=1000'
{"query":{"pages":{"1000":{"pageid":1000,"ns":0,"title":"Hercule Poirot","contentmodel":"wikitext","pagelanguage":"en","touched":"2015-06-22T16:44:05Z","lastrevid":668143333,"length":59801}}}}
[root@zetawiki ~]# curl -s 'https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info&pageids=1000' | jq .
{
  "query": {
    "pages": {
      "1000": {
        "pageid": 1000,
        "ns": 0,
        "title": "Hercule Poirot",
        "contentmodel": "wikitext",
        "pagelanguage": "en",
        "touched": "2015-06-22T16:44:05Z",
        "lastrevid": 668143333,
        "length": 59801
      }
    }
  }
}

6 같이 보기[ | ]

7 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}