Comments (5)
Understood, and thanks for piping up. Your issue actually surfaced a bug in how jo
handles reads from stdin, and I'll push out a PR to fix it in short order.
Also, if I understand correctly, you're basically trying to convert a JSON Lines document into a JSON array. That's actually quite easily done in one Bash line, no jo
or loops necessary:
( readarray -t lines < full-dataset.json ; IFS=, ; echo "[${lines[*]}]" ) > single-array.json
(The use of a subshell is just so I don't have to clean up lines
and reset IFS
.)
from jo.
I can replicate both your issues on macOS. jo
on Linux handles bad-inference.json
just fine:
linux$ jo -a < bad-inference.json
[{"timezone":"Africa/Algiers","cities":["Abou el Hassan"...
but treats utf-8-crash.json
as a string:
linux$ jo -a < utf-8-crash.json
["{\"timezone\":\"Asia/Kolkata\",\"cities\":[\"Abhayāpuri\",\"Abohar\",...
So something's hinky here, but the stopgap solution is already documented in the jo
man page:
jo normally treats value as a literal string value, unless it begins with one of the following characters:
value action
──────────────────────────────────────────────────────────────────────────
@file substitute the contents of file as-is
%file substitute the contents of file in base64-encoded form
:file interpret the contents of file as JSON, and substitute the result
jo -a :utf-8-crash.json
and jo -a :bad-inference.json
work exactly as advertised on both Linux and macOS.
from jo.
That may well be, but that's not how this data is being passed to jo in my use case. It's only written to a file so that was able to pass provide the data here. The data is being piped to jo and both examples are just a single record from a big pile of similar ones.
That said, I'd be happy to ingest the data via a tempfile on disk, but because it isn't a valid json file (it's a json object per line), jo refuses to ingest it.
Here's what the loop which generates the json looks like, to give you a better idea of my use case:
while IFS="|" read -r timezone cities; do
jo timezone="$timezone" \
cities="$(while read -rd ";" city; do echo "$city"; done <<<"${cities};" | jo -a)"
done < "$sqlite_out" | jo -a > "$json_out"
This problem is already solved (using a very ugly string concatenating loop), so I do have a working stopgap solution. I'm not here because I can't solve the problem, I just figured you might be interested in the issue. And truthfully I would love to be able to use jo for this kind of work, it makes it so much more convenient.
from jo.
@nikcorg we’ve just merged a patch by @gromgit which addresses reading long lines in jo
. Would you like to see if this fixes your use-case?
from jo.
Yes it does. Thank you both very much :-)
from jo.
Related Issues (20)
- RFE: Do not split quoted keys with -d HOT 2
- Gaps in variable HOT 2
- Delete nested element HOT 5
- Assertion `utf8_validate(str)' failed - again? HOT 9
- Generating JSON and including JSON output from another program appears to result in double encoded JSON? HOT 3
- Suberflous `\` if try to escape `}` in value HOT 8
- feature allow string vals with spaces deep nested HOT 1
- Question: how to produce multiline strings? HOT 2
- Passing an empty file with `@` syntax now throws an error on 1.7 HOT 5
- FAIL: tests/jo.test 20 - read json array elements HOT 7
- 1.9 build for Windows missing HOT 1
- jo will drop the trailing newline at the end of file HOT 8
- Dynamic array of nested oneofs HOT 1
- Disable type coercion HOT 6
- possible bug: use of `-a` on outer command in nested jo fails to render inside object element when space exists in internal object property value HOT 2
- Modifications to GPLv2 license make jo difficult to adopt in enterprise environment HOT 2
- Please support empty array HOT 1
- pass multiple variables to jo? HOT 3
- jo extends fractional part of some floats HOT 2
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 jo.