Categories
Posts

jo, Create JSON On The Command Line

Do you remember jq, the tool that makes it easy it parse JSON on the command line? Have you ever wondered what the opposite of jq would be?

The answer is jo. It simplifies the process of creating JSON on the command line. Here is one of the simple examples the author listed:

> jo time=$(date +%s) dir=$HOME
{"time":1457195712,"dir":"/Users/jpm"}

Along with a more interesting one:

> jo -p name=JP object=$(jo fruit=Orange point=$(jo x=10 y=20) number=17) sunday=false
{
   "name": "JP",
   "object": {
      "fruit": "Orange",
      "point": {
         "x": 10,
         "y": 20
      },
      "number": 17
   },
   "sunday": false
}

This would be handy for writing to JSON Lines log files.

One reply on “jo, Create JSON On The Command Line”

Leave a Reply

Your email address will not be published. Required fields are marked *