violet-php / streaming-json-encoder Goto Github PK
View Code? Open in Web Editor NEWPHP library for iteratively encoding large JSON documents piece by piece
Home Page: http://violet.riimu.net
License: MIT License
PHP library for iteratively encoding large JSON documents piece by piece
Home Page: http://violet.riimu.net
License: MIT License
Not an issue, but a request for an example.
Before I start testing with it, is it possible for your JSON stream library to create more complex objects? For example, I have a generator which will give arrays to output, but they go in a subsection of the response json:
{
"@count": 37,
"@data": [
{
"id": 1,
"name": "bob"
},
...more items
]
}
My generator only creates the items which go under @data
. Can you give an example of how this could be done? Or is it as easy as just passing in another buffer encoder as a value to the top level encoder?
I'll probably play with this later today. If you have time to answer, that would help a lot.
If a BufferJsonEncoder encodes a Generator, or a value that points to a Generator, JsonStream is no longer seekable. This breaks passing JsonStream as the response body of some frameworks. Slim v4 in particular attempts to read the first byte of a seekable body to determine if the response is empty, then rewinds.
The exception triggered is Cannot rewind a generator that was already run
, caused by calling AbstractJsonEncoder::getIterator() twice on the same generator (JsonBuffer::rewind() calls AbstractJsonEncoder::rewind() which resets the stack).
I am pretty sure it's impossible to make JsonStream detect if it's safe to return isSeekable()==true, but I think it would be useful to have a setSeekable(bool $value) method to mark a stream as unseekable for such cases.
The content type in the HTTP Header is always "Content-Type: text/html; charset=UTF-8".
For JSON this should be "Content-Type: application/json; charset=UTF-8"
Setting the header manually did not work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.