jq pattern for terrible JSON

Many JSON formats are completely brain dead. Instead of the natural { key : value }, these formats go “all meta’, using { Field: “name”, Value: “amateur” } or { “name” : “name”, “value”: “amateur” }. This “meta key-value” approach is a stupid format that doesn’t provide any extra extensibility, yet completely destroys the concept of a useful schema.

This poor design also complicates json query (jq) (see cookbook too)

The recipe to extract the value you want:

$ jq -r '.[] | select( .Field == "properties").Value' output.json
this is a terrible design

With this input file:

$ cat output.json
[
  {
    "Field": "description",
    "Value": "human description of a terrible design"
  },
  {
    "Field": "enabled",
    "Value": true
  },
  {
    "Field": "id",
    "Value": "fa722ed8b4f56d14bcf77537"
  },
  {
    "Field": "name",
    "Value": "your-name"
  },
  {
    "Field": "properties",
    "Value": "this is a terrible design"
  }
]
This entry was posted in Software Engineering. Bookmark the permalink.

Comments are closed.