Lurker News

Comments (120) 40 threads

Earlier comments
kara_jade1 reply#
You can do this easily with the json_tree function from SQLite's JSON1 extension. It's given as an example in the documentation:

https://sqlite.org/json1.html#jtree

  SELECT big.rowid, fullkey, value
    FROM big, json_tree(big.json)
   WHERE json_tree.type NOT IN ('object','array');
ComputerGuru#
And with the fileio sqlite extension, you can even directly query files (and their contents, and directories recursively too, no less) from SQL.
nfoz1 reply#
That's nice, I like that.

Related, if you want more of a csv-style, see JSONLines. aka "newline-delimited JSON"
http://jsonlines.org/

emmelaich2 replies#
I don't see what jsonlines has over yaml; in fact the jsonlines examples presented there are almost trivially converted to yaml. e.g. the first example is valid yaml if you add a '- ' to each line.

And JSON is (almost) a perfect subset of yaml.
I've been using csv lately. It's reputation is overstated.
What I like is that it's far more compact than yaml or json and trivially pulled into sqlite for ad-hoc queries.

mirimir#
> ... and trivially pulled into sqlite for ad-hoc queries.

Or spreadsheets, to work out a plan, and then MySQL.

geofft#
One thing I like about JSON Lines is robustness to bad data - if an individual line is corrupted, you can discard it / print a warning and move on, and the parser can start again at the next newline. This makes it useful for log messages / metrics, because if something crashes while emitting a log line, you can recover. If something crashes while emitting an item in a YAML list, you might corrupt the entire rest of the document.

Another is that it makes streaming processing a little easier. Once you have a line, you know you can attempt to process it, and you can shard processing on newlines without a full YAML processor. Tools that work on newlines or tools that can just split on lines can handle the first level of JSON Lines output.

ravinizme#
Similar to python-jsonpipe (8 years ago).

https://github.com/zacharyvoase/jsonpipe
It includes 'jsonunpipe'.
So you could grep part of the JSON and still get a JSON back.
``` echo '{"a": 1, "b": 2}' |grep b| jsonpipe | jsonunpipe
#{""b": 2} ```

Load more comments