ring-swagger & compojure-api
borkdude 2019-09-09T14:03:59.005Z

@niklas.collin I believe cheshire can do this lazily

Empperi 2019-09-09T14:04:32.005500Z

Yeah could be. I ended up actually writing JSONL format which suits better in my use case

Empperi 2019-09-09T14:04:56.006Z

And for that jsonista works just fine since I write a new JSON object per line

borkdude 2019-09-09T14:05:13.006400Z

There's also a command line tool which supports streaming: https://github.com/borkdude/jet

Empperi 2019-09-09T14:06:00.006900Z

nice. Doesn't support Windows though, at least the installer doesn't 😜

borkdude 2019-09-09T14:06:27.007400Z

is JSONL just writing json objects, one on each line?

Empperi 2019-09-09T14:06:33.007700Z

And apparently it does graalvm native compilation

Empperi 2019-09-09T14:06:38.008Z

Yeah, it basically is

Empperi 2019-09-09T14:06:46.008300Z


Empperi 2019-09-09T14:06:59.008800Z

It's like "better CSV"

borkdude 2019-09-09T14:08:06.010100Z

that's right, no pre-built Windows, but if you build one on your own machine it may work in Windows. Also you can maybe use it from the JVM, but in that case, I would just look at how streaming was implemented and copy it. But probably jsonista already supports it like that (passing a reader, read objects until you hit EOF).

Empperi 2019-09-09T14:08:36.010500Z


borkdude 2019-09-09T14:08:55.010900Z


Empperi 2019-09-09T14:09:09.011200Z

and actually on windows powershell can do that stuff out of the box excluding edn/transit stuff of course

borkdude 2019-09-09T14:09:28.011500Z

that's nice. there may also be a jq for Windows

Empperi 2019-09-09T14:09:41.011800Z

I guess there is but can't see why I would use one 🤷

Empperi 2019-09-09T14:09:48.012Z

when native tools work just fine

borkdude 2019-09-09T14:10:28.012600Z

right. can you show me an example of how you use it in Powershell? PS also runs on Linux and Mac nowadays

Empperi 2019-09-09T14:11:20.012900Z

well, it of course totally depends on what one is doing...

Empperi 2019-09-09T14:11:24.013100Z

but a random example:

Empperi 2019-09-09T14:12:07.014Z

(irm <http://foo.bar/some.json>).somePathInJsonObject.andAnother | select key1,key2

Empperi 2019-09-09T14:12:17.014300Z

would handle json which would be of format:

Empperi 2019-09-09T14:13:14.015400Z

{"somePathInJsonObject": {"andAnother": [{"key1": 1, "key2": 2, "key3": 3}, {"key1": 4, "key2": 5, "key3": 6}]}}

Empperi 2019-09-09T14:13:37.015900Z

and naturally objects could have more keys and in this example it would retrieve the values in the array but only keys key1 and key2

Empperi 2019-09-09T14:14:04.016300Z

and if one passes the result into Format-Table then it gets rendered as a nice table

Empperi 2019-09-09T14:14:18.016700Z

but that is not very usable anymore since then data isn't objects anymore

Empperi 2019-09-09T14:14:30.017Z

then one would have to go to the *nix way of string manipulation 🙂

borkdude 2019-09-09T14:16:44.017400Z

Ah. Just for fun I tried this with jet:

$ jet --from json --keywordize --query '[:somePathInJsonObject :andAnother (map (select-keys [:key1 :key2]))]' &lt;&lt;&lt; '{"somePathInJsonObject": {"andAnother": [{"key1": 1, "key2": 2, "key3": 3}, {"key1": 4, "key2": 5, "key3": 6}]}}'
[{:key1 1, :key2 2} {:key1 4, :key2 5}]

borkdude 2019-09-09T14:18:21.017600Z

thanks for showing the example

borkdude 2019-09-09T14:19:29.018200Z

but tl;dr: lazily consuming elements of a top-level array is something cheshire supports, jsonista, don't know

ikitommi 2019-09-09T14:41:11.022300Z

jsonista is 1:1 wrapper for Jackson Databind, which is not by default, streaming. Databind builds on top of Jackson Streaming could be exposed in jsonista. PRs most welcome.

borkdude 2019-09-09T14:41:57.022800Z

yeah, I guess the most common use case is top level objects streaming which you now can already do with an inputstream or reader

ikitommi 2019-09-09T14:42:02.023100Z

JsonFactory f = mapper.getFactory(); // may alternatively construct directly too

// First: write simple JSON output
File jsonFile = new File("test.json");
JsonGenerator g = f.createGenerator(jsonFile);
// write JSON: { "message" : "Hello world!" }
g.writeStringField("message", "Hello world!");

// Second: read file back
JsonParser p = f.createParser(jsonFile);

JsonToken t = p.nextToken(); // Should be JsonToken.START_OBJECT
t = p.nextToken(); // JsonToken.FIELD_NAME
if ((t != JsonToken.FIELD_NAME) || !"message".equals(p.getCurrentName())) {
   // handle error
t = p.nextToken();
if (t != JsonToken.VALUE_STRING) {
   // similarly
String msg = p.getText();
System.out.printf("My message to you is: %s!\n", msg);

ikitommi 2019-09-09T14:43:03.024100Z

yes, true that. Does that apply also to writing a lazy sequence into outputstream?