{"id":1085,"date":"2020-05-10T13:44:58","date_gmt":"2020-05-10T18:44:58","guid":{"rendered":"http:\/\/tiemensfamily.com\/TimOnCS\/?p=1085"},"modified":"2020-05-10T13:44:58","modified_gmt":"2020-05-10T18:44:58","slug":"jq-pattern-for-terrible-json","status":"publish","type":"post","link":"https:\/\/tiemensfamily.com\/timoncs\/2020\/05\/10\/jq-pattern-for-terrible-json\/","title":{"rendered":"jq pattern for terrible JSON"},"content":{"rendered":"<p>Many JSON formats are completely brain dead.  Instead of the natural { key : value }, these formats go &#8220;all meta&#8217;, using { Field: &#8220;name&#8221;, Value: &#8220;amateur&#8221; } or { &#8220;name&#8221; : &#8220;name&#8221;, &#8220;value&#8221;: &#8220;amateur&#8221; }.  This &#8220;meta key-value&#8221; approach is a stupid format that doesn&#8217;t provide any extra extensibility, yet completely destroys the concept of a useful schema. <\/p>\n<p>This poor design also complicates <a href=\"https:\/\/stedolan.github.io\/jq\/\">json query<\/a> (<a href=\"https:\/\/stedolan.github.io\/jq\/manual\/\">jq<\/a>) (see <a href=\"https:\/\/github.com\/stedolan\/jq\/wiki\/Cookbook\">cookbook<\/a> too)<\/p>\n<p>The recipe to extract the value you want:<\/p>\n<pre>$ jq -r '.[] | select( .Field == \"properties\").Value' output.json\nthis is a terrible design<\/pre>\n<p>With this input file:<\/p>\n<pre>$ cat output.json\n[\n  {\n    \"Field\": \"description\",\n    \"Value\": \"human description of a terrible design\"\n  },\n  {\n    \"Field\": \"enabled\",\n    \"Value\": true\n  },\n  {\n    \"Field\": \"id\",\n    \"Value\": \"fa722ed8b4f56d14bcf77537\"\n  },\n  {\n    \"Field\": \"name\",\n    \"Value\": \"your-name\"\n  },\n  {\n    \"Field\": \"properties\",\n    \"Value\": \"this is a terrible design\"\n  }\n]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Many JSON formats are completely brain dead. Instead of the natural { key : value }, these formats go &#8220;all meta&#8217;, using { Field: &#8220;name&#8221;, Value: &#8220;amateur&#8221; } or { &#8220;name&#8221; : &#8220;name&#8221;, &#8220;value&#8221;: &#8220;amateur&#8221; }. This &#8220;meta key-value&#8221; approach &hellip; <a href=\"https:\/\/tiemensfamily.com\/timoncs\/2020\/05\/10\/jq-pattern-for-terrible-json\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/1085"}],"collection":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/comments?post=1085"}],"version-history":[{"count":0,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/1085\/revisions"}],"wp:attachment":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/media?parent=1085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/categories?post=1085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/tags?post=1085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}