Tip: Convert filtered JSON to a CSV #32
kellyjonbrazil
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Since
jello
gives you the full power of the python interpreter, you can not only filter the JSON, but you can also convert the output format to non-nativejello
output formats, like CSV.For example, let's take the output of
jc -a
, which gives us some metadata about thejc
program in JSON format. Inside the JSON is an array calledparsers
that contains the metadata about each parser. Let's usejello
to filter just the parsers that are compatible with Windows and output that information as a CSV.Here is the
jello
query:As you can see, we are simply importing the
csv
module and writing to aStringIO
object with thecsv.DictWriter
method. The query is assigned toq
and used inside thewriter.writerows()
function. The output is being redirected to a file namedwin32.csv
. We use theprint()
function to bypassjello
's JSON conversion logic.The output is a standard CSV file:
The same can be done with other output-types like YAML, etc.
Beta Was this translation helpful? Give feedback.
All reactions