Comments (4)
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.
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.
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.
@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)
- Inconsistent result when using `$*`
- Double-width characters spoil column alignment HOT 4
- `mlr --icsv --ojson cat < mlr.bug.csv` drops some columns HOT 5
- Add description for "put" verb HOT 1
- 'mlr cut' is very slow HOT 8
- mlr --otsv does not handle broken quotes correctly compared to --ocsv HOT 6
- JSON to CSV Error HOT 8
- exit code = 1 for --csv skip-trivial-records and csv file's last record is blank
- Automated way of clearing down column data HOT 7
- JSON flag documentation question HOT 1
- Equivalent to Excel function "data load from folder" then "combine and load" multiple CSV's finally "apply transformations" HOT 7
- Find and remove "string" retaining all other row data HOT 5
- Find and replace special character & with and using ssub HOT 2
- Add a `stat` DSL function HOT 4
- Notwithstanding --skip-comments, double-quoted tokens in comment are mishandled with any --c2* option HOT 3
- Completely unexpted output of put, then cut, then label HOT 3
- do we have python binding? HOT 1
- About `--transpose` in the documentation
- newlines in fields | CSV file: Header/data length mismatch HOT 4
- More than one blank line at the end of CSV file: automate cleanup?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miller.