CLI로 json을 인코딩하는 jq 명령
내용
과제 : 터미널에서 curl 명령으로 API를 쳤을 때 응답이 깨집니다.
$ curl http://weather.livedoor.com/forecast/webservice/json/v1\?city=130010 | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8249    0  8249    0     0   207k      0 --:--:-- --:--:-- --:--:--  211k
{
    "pinpointLocations": [
        {
            "link": "http://weather.livedoor.com/area/forecast/1310100",
            "name": "\u5343\u4ee3\u7530\u533a"
        },
        {
            "link": "http://weather.livedoor.com/area/forecast/1310200",
            "name": "\u4e2d\u592e\u533a"
        },
        {
            "link": "http://weather.livedoor.com/area/forecast/1310300",
            "name": "\u6e2f\u533a"
        },
        {
            "link": "http://weather.livedoor.com/area/forecast/1310400",
            "name": "\u65b0\u5bbf\u533a"
        },
        {
            "link": "http://weather.livedoor.com/area/forecast/1310500",
            "name": "\u6587\u4eac\u533a"
        },
        {
            "link": "http://weather.livedoor.com/area/forecast/1310600",
            "name": "\u53f0\u6771\u533a"
        },
# 略
구누 누 ...
jq라는 도구 사용
$ brew install jq
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
kobalt                                                                                                                               makeself
==> Installing dependencies for jq: oniguruma
==> Installing jq dependency: oniguruma
==> Downloading https://homebrew.bintray.com/bottles/oniguruma-6.1.3.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring oniguruma-6.1.3.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/oniguruma/6.1.3: 17 files, 1.3M
==> Installing jq
==> Downloading https://homebrew.bintray.com/bottles/jq-1.5_2.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring jq-1.5_2.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/jq/1.5_2: 18 files, 957.9K
➜  ~ which jq
/usr/local/bin/jq
한 번 더 두드리는
curl http://weather.livedoor.com/forecast/webservice/json/v1\?city=130010 | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8249    0  8249    0     0   184k      0 --:--:-- --:--:-- --:--:--  187k
{
  "pinpointLocations": [
    {
      "link": "http://weather.livedoor.com/area/forecast/1310100",
      "name": "千代田区"
    },
    {
      "link": "http://weather.livedoor.com/area/forecast/1310200",
      "name": "中央区"
    },
    {
      "link": "http://weather.livedoor.com/area/forecast/1310300",
      "name": "港区"
    },
    {
      "link": "http://weather.livedoor.com/area/forecast/1310400",
      "name": "新宿区"
    }
# 略
그래, 괜찮아.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(CLI로 json을 인코딩하는 jq 명령), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/emahiro/items/c5acba5bf52d99f71d56
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
$ brew install jq
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
kobalt                                                                                                                               makeself
==> Installing dependencies for jq: oniguruma
==> Installing jq dependency: oniguruma
==> Downloading https://homebrew.bintray.com/bottles/oniguruma-6.1.3.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring oniguruma-6.1.3.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/oniguruma/6.1.3: 17 files, 1.3M
==> Installing jq
==> Downloading https://homebrew.bintray.com/bottles/jq-1.5_2.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring jq-1.5_2.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/jq/1.5_2: 18 files, 957.9K
➜  ~ which jq
/usr/local/bin/jq
curl http://weather.livedoor.com/forecast/webservice/json/v1\?city=130010 | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8249    0  8249    0     0   184k      0 --:--:-- --:--:-- --:--:--  187k
{
  "pinpointLocations": [
    {
      "link": "http://weather.livedoor.com/area/forecast/1310100",
      "name": "千代田区"
    },
    {
      "link": "http://weather.livedoor.com/area/forecast/1310200",
      "name": "中央区"
    },
    {
      "link": "http://weather.livedoor.com/area/forecast/1310300",
      "name": "港区"
    },
    {
      "link": "http://weather.livedoor.com/area/forecast/1310400",
      "name": "新宿区"
    }
# 略
Reference
이 문제에 관하여(CLI로 json을 인코딩하는 jq 명령), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/emahiro/items/c5acba5bf52d99f71d56텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)