ã³ãã³ãã©ã¤ã³ã§Perlã£ã½ãhashã§æ¸ãã¦ããã£ã¨JSONçæãããã¤ä¾¿å©
ã³ãã³ãã»ã©ã¤ã³ã§JSONãããæãã«æ´å½¢ããã®ã«ãã jq ã³ãã³ã使ãã¾ããããã®éã§ããã£ã¨JSONæ¸ããããªã¼ã£ã¦æã«ä¾¿å©ã ãªã¨æã£ã¦ããã¤ãããã®ã§ç´¹ä»ããã¦ãã ãã
ãããªæãã§ä½¿ãããã¤ã§ããPerlã£ã½ãhashã§æ¸ãã¦JSONçæã§ãã
$ jg '{a => b}' { "a" : "b" } $ jg '{query => {prefix => {value => "di"}}, filter => {term => {is_delete => 0}} }' { "filter" : { "term" : { "is_delete" : 0 } }, "query" : { "prefix" : { "value" : "di" } } }
Elasticsearchã®APIãçã§ä½¿ãæã¨ãã«ä¾¿å©ã ã¨æã£ã¦ã¾ãã
ãã¨ãã°ãããªãããã§ããã
$ jg '{query => {prefix => {value => "di"}}, filter => {term => {is_delete => 0}} }' | curl -XPOST http://localhost:9200/indices/table/_search (å²æ)
ãã¡ããPerl ã® JSON::XS ã¢ã¸ã¥ã¼ã«å
¥ã£ã¦ãç°å¢ãããªãã¨åºæ¥ã¾ãã
$ cpanm JSON::XS
ããã¨json_xsã£ã¦ã³ãã³ãã使ããããã«ãªãã®ã§ãããããã使ã£ã¦ä»¥ä¸ã®æ§ãª function ã .zshrc ãä½ãã«æ¸ãã¦ããã¾ãã
function jg(){ echo "$@" | json_xs -f eval }
追è¨:
ã¡ãªããæ¸ãå¿ãã¾ããã
- ã±ãã«ã³ããã«ããªãã¦ãã
- æå¤ã¨validãªJSONæ¸ãã®å¤§å¤ã¨ããã®ã楽ã«ãªã(æ§æã¨ã©ã¼ãããããããããªã)