This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-09
Channels
- # announcements (5)
- # beginners (53)
- # clj-kondo (4)
- # cljdoc (3)
- # cljs-dev (11)
- # cljsjs (1)
- # clojure (59)
- # clojure-europe (15)
- # clojure-italy (6)
- # clojure-nl (9)
- # clojure-spec (22)
- # clojure-uk (26)
- # clojurescript (16)
- # clojutre (6)
- # cursive (27)
- # datomic (34)
- # duct (1)
- # figwheel-main (2)
- # fulcro (12)
- # graphql (14)
- # jackdaw (9)
- # jobs (1)
- # kaocha (4)
- # luminus (1)
- # off-topic (11)
- # pathom (1)
- # pedestal (2)
- # re-frame (6)
- # reagent (10)
- # ring-swagger (34)
- # shadow-cljs (47)
- # spacemacs (21)
- # sql (3)
- # tools-deps (37)
- # uncomplicate (11)
- # vim (17)
@niklas.collin I believe cheshire can do this lazily
Yeah could be. I ended up actually writing JSONL format which suits better in my use case
There's also a command line tool which supports streaming: https://github.com/borkdude/jet
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).
and actually on windows powershell can do that stuff out of the box excluding edn/transit stuff of course
right. can you show me an example of how you use it in Powershell? PS also runs on Linux and Mac nowadays
{"somePathInJsonObject": {"andAnother": [{"key1": 1, "key2": 2, "key3": 3}, {"key1": 4, "key2": 5, "key3": 6}]}}
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
Ah. Just for fun I tried this with jet:
$ jet --from json --keywordize --query '[:somePathInJsonObject :andAnother (map (select-keys [:key1 :key2]))]' <<< '{"somePathInJsonObject": {"andAnother": [{"key1": 1, "key2": 2, "key3": 3}, {"key1": 4, "key2": 5, "key3": 6}]}}'
[{:key1 1, :key2 2} {:key1 4, :key2 5}]
but tl;dr: lazily consuming elements of a top-level array is something cheshire supports, jsonista, don't know
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.
yeah, I guess the most common use case is top level objects streaming which you now can already do with an inputstream or reader
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.writeStartObject();
g.writeStringField("message", "Hello world!");
g.writeEndObject();
g.close();
// 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);
p.close();