Comments (9)
just incase anyone is interested in a work around for this issue
(ring.util.io/piped-input-stream
(fn [out] (->> out
(OutputStreamWriter.)
(BufferedWriter.)
(cheshire.core/generate-stream data))))
from cheshire.
Okay, let me make sure I have this correct in my understanding.
Would it be helpful to have something like:
(def mydata {:foo "bar" :etc "...etc..."})
;; of InputStream type
(def my-inputstream (ring/get-response-inputstream))
;; with "generate-to-stream" or whatever it's named to be added:
(json/generate-to-stream mydata my-inputstream)
? (this is heavily pseudo-coded since I don't know exactly what it looks like from the ring side)
from cheshire.
Also, I'm not quite sure what you mean by a "lazy seq of strings", since the usual output from generate-string
is a single string; can you elaborate? (I'm not familiar with what enlive does in this case)
from cheshire.
The simplest case would be
(json/generate-to-stream my-data) ;; returns an input stream
Then the input stream could be returned as the response body to the ring adapter which would read from it and shoot the bytes down the wire as needed.
The lazy seq of strings tactic would be something like
(json/generate-strings {:foo [1 2 3]})
;; => ("{" "\"foo\"" ":" "[" "1" "," "2" "," "3" "]" "}")
how exactly the string is broken up isn't as important as the fact that it's lazy, and so the whole thing doesn't have to be assembled into a single spot in memory -- it can be consumed by the ring adapter lazily, in a manner analogous to using an InputStream
.
from cheshire.
Okay, that clarifies it; thanks!
from cheshire.
@fredericksgary You may also want to check out the cheshire.experimental
namespace, as we've been experimenting with stream parsing in there.
from cheshire.
+1 on this, and I don’t understand how to employ @boxxxie’s suggested workaround.
from cheshire.
@aviflax Use this function to turn data into an output stream:
(defn generate-stream
([data] (generate-stream data nil))
([data options]
(ring.util.io/piped-input-stream
(fn [out] (cheshire.core/generate-stream data
(-> out
(OutputStreamWriter.)
(BufferedWriter.))
options)))))
from cheshire.
Endpoints from systems like ElasticSearch package results as multiple top level objects, which facilitates this.
from cheshire.
Related Issues (20)
- Always update to latest version of Jackson, when available
- Any way to not escape the quotes HOT 2
- Suggestion: prove equivalence with clojure.data.json HOT 6
- Add support for capturing source position/locations when parsing HOT 2
- Allow key-fn like hook for value HOT 2
- Converting nested fields from java objects to clojure types doesnot work
- Custom conversion when parsing?
- `parsed-smile-seq` actually parses JSON
- Run tests against JSONTestSuite
- Resulting Array from parse not processed lazily HOT 1
- :key-fn no longer works in generate-string? HOT 1
- Using the Ubuntu Cheshire package with Clojure HOT 1
- lein unable to find cheshire on classpath HOT 1
- Security vulnerability in Jackson dependency HOT 4
- Can't convert object of type org.postgresql.util.PGobject HOT 1
- support jackson's fast number parsing/writing features HOT 1
- Update test.generative HOT 2
- Possible to support parsing copy-paste JSON? HOT 1
- Test failures with Java 21
- Deterministic parse and generate HOT 1
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 cheshire.