14.06.2014 20:23

Transforming JSON to CSV

CERTs are all about processing information security notifications. Most of the time, these arrive in the form of CSV files. However, occasionally we do get some JSON data. While CSV is line oriented, JSON allows for more complex structures (arrays, objects, objects in objects, etc.)

So how to you easily transform complex JSON structures to CSV? Most programmers would look at the specific JSON format and start writing a converter. However, there is a smarter way: JQ!

JQ is a JSON filter / transform mechanism.

To quote JQ's homepage: "A jq program is a 'filter': it takes an input, and produces an output. There are a lot of builtin filters for extracting a particular field of an object, or converting a number to a string, or various other standard tasks."

In short: JQ is like awk and xargs for JSON. Mightly practical stuff!

Author: L. Aaron Kaplan