jsonstreamingparser | A JSON streaming parser implementation in PHP | Parser library
kandi X-RAY | jsonstreamingparser Summary
kandi X-RAY | jsonstreamingparser Summary
[License] This is a simple, streaming parser for processing large JSON documents. Use it for parsing very large JSON documents to avoid loading the entire thing into memory, which is how just about every other JSON parser for PHP works. For more details, I’ve written up a longer explanation of the [JSON streaming parser] that talks about pros and cons vs. the standard PHP JSON parser. If you’ve ever used a [SAX parser] for XML (or even JSON) in another language, that’s what this is. Except for JSON in PHP. This package is compliant with [PSR-4] [PSR-1] and [PSR-2] If you notice compliance oversights, please send a patch via pull request. To use the JsonStreamingParser you just have to implement the \JsonStreamingParser\Listener interface. You then pass your Listener into the parser. That’s it! Your Listener will receive events from the streaming parser as it works. There is a complete example of this in example/example.php.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Consume a single character .
- Parse the stream .
- Start an object .
- Force the end of the document .
- Convert a Unicode codepoint to a character .
- Get the object path .
- Insert a value into the stack .
- End the current object .
- End a complex value
- Convert string to number
jsonstreamingparser Key Features
jsonstreamingparser Examples and Code Snippets
Community Discussions
Trending Discussions on jsonstreamingparser
QUESTION
I've read somewhere that I should use the library salsify/jsonstreamingparser
to open a big json file but it's giving me the same error as with json_decode
:
ANSWER
Answered 2018-Sep-19 at 11:06Using the InMemoryListener certainly defeats the purpose of a streaming parser. That'll just unpack everything into memory (likely worse memory-wise than plain json_decode
).
You'll need to catch each JSON object block individually, if you want to work under such constraints.
There's the SimpleObjectQueueListener which could possibly fit the bill. If the specific JSON has a bunch of [{…}, {…}, {…}]
objects to be processed:
QUESTION
I have a JSON file:
...ANSWER
Answered 2018-Jul-23 at 17:37The GeoJSONListener does exactly what you want to do - it keeps the second level of the objects in memory. That way it loads each MLM object in your file by itself - it does not load the complete file into memory.
Testing out the code you have included on the file you've referenced (and reducing memory limit to 32M, since a streaming parser shouldn't need 4G of memory), it parses through the whole file, reading through 27200 objects before I cancelled the process, in about 10 minutes on an old Macbook.
This leads me to believe that the problem isn't related to your JSON parser or how you're parsing the file, and can possibly be caused by something else (like your host / web server not honouring calls to set_time_limit
or your database layer locking or barfing on some content.
QUESTION
I am working with large heavily nested JSON file, and want to use streaming parser by implementing a Listener interface found on jsonstreamingparser. When I ran by php code, I receiced this error: Fatal error: Uncaught Error: Class 'InMemoryListener' not found in C:\xampp\htdocs. I think the error is on line that contains "$listener = new InMemoryListener();". I am new to using stream parser for JSON in PHP. I know what listener interface does is similar to what XMLPARSER does, and some kind of PHP listener interface has been created by some gurus, but I do not know how to implement it in my code. I put the supposed listener interface file named "InMemoryListener" in the same folder as my php code, but I still got error. Can anyone explain how I can implement the Listener interface in my code? Below is my code:
...ANSWER
Answered 2017-Oct-04 at 04:15When you install something with composer you need to ensure that composer's autoloader is included in your script execution. Add this to the top of your file:
QUESTION
So, I have a large JSON file and I want to insert data from that file to MySQL database. I can only use PHP 5.6 and can't change php.ini file.
When I'm using json_decode()
, I get error, that there is to much memory to allocate. So I searched for some kind of library and I found this library and I'm using it like that:
ANSWER
Answered 2017-Jul-27 at 07:45You need to set the option via ini_set
: http://php.net/manual/en/function.ini-set.php
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install jsonstreamingparser
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page