loading...

Convert JSON to CSV using JSON path expressions with Sqlify.io

moboudra profile image Mohamed Boudra ・1 min read

JSON paths are a very simple and intuitive way to reference elements in JSON documents, similar to CSS selectors, but for JSON.

This is how it works, if you had a document like this:

[
  {
    "name": "Christopher",
    "age": "23",
  },
  {
    "name": "Michael",
    "age": "45",
  }
]

You could extract the names of all the person records with this expression:

$.*.name

where:

  • $ references the root element, in this case an array
  • * is to repeat the expression, so it will match on each object of the array
  • name is to get the name property of the object

So if you used this expression to convert to CSV, this would result in:

name
Christopher
Michael

This is very useful when you need to flatten very complex JSON documents, and you only want to extract a few fields.

Go ahead and try our custom JSON to CSV conversion tool. Any feedback is welcome!

Discussion

pic
Editor guide