Giter Club home page Giter Club logo

Comments (4)

smammy avatar smammy commented on June 2, 2024 1

Just thinking out loud here… Miller is pretty forgiving about JSON input. All of these are interpreted as two records:

# One JSON document, an array of two objects
echo '[{"foo":"bar"},{"foo":"baz"}]' | mlr -j cat
# "JSON Lines" - two JSON documents, one object each
echo -e '{"foo":"bar"}\n{"foo":"baz"}' | mlr -j cat
# Neither, but still accepted
echo '{"foo":"bar"}{"foo":"baz"}' | mlr -j cat

The output is normally a single JSON document consisting of an array, but if --no-jlistwrap is set, it's a JSON Lines document.

I wonder if the JSON input reader could set --no-jlistwrap if it encountered input other than a JSON array?

from miller.

johnkerl avatar johnkerl commented on June 2, 2024

So @smammy ... it turns out this was intentional on my part.

Here:
https://github.com/johnkerl/miller/blob/6.11.0/pkg/output/record_writer_json.go#L56-L88
the idea is that mlr --json cat /dev/null should produce [].

However -- I am questioning that. For example, jq . /dev/null produces nothing at all and ostensibly Miller shouldn't either. 🤔

from miller.

johnkerl avatar johnkerl commented on June 2, 2024

Also:

$ echo '' | jq .

$ echo '[]' | jq .
[]

$ echo '' | mlr --json cat
[
]

$ echo '[]' | mlr --json cat
[
]

It's easy for me to make those last two both empty, or both [] ... issue is, Miller "forgets" the outer [] provided on input, even when it's explicitly provided as input, so:

  • I don't like empty input leading to [] output
  • I don't like [] input leading to empty output
  • I'm not seeing a clean way for the JSON-output writer to know which came in in the first place ...

from miller.

johnkerl avatar johnkerl commented on June 2, 2024

@smammy yes, I think something like that.

I don't want to mutate CLI arguments per se, but, in the context struct that comes in with each record, I can put a JSON-had-brackets flag. So the JSON record-reader can set this on the end-of-stream marker, and the JSON record-writer can consult it, and all other format-specific record-readers and record-writers can ignore it.

from miller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.