GithubHelp home page GithubHelp logo

metaworx / jsonstreamingparser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from salsify/jsonstreamingparser

0.0 2.0 0.0 188 KB

A JSON streaming parser implementation in PHP.

License: MIT License

PHP 98.31% Makefile 1.69%

jsonstreamingparser's Introduction

Streaming JSON parser for PHP

Build Status GitHub tag Packagist Minimum PHP Version 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.

Installation

To install JsonStreamingParser you can either clone this repository or you can use composer

composer require salsify/json-streaming-parser

Usage

To use the JsonStreamingParser you just have to implement the \JsonStreamingParser\Listener interface. You then pass your Listener into the parser.

For example:

$stream = fopen('doc.json', 'r');
$listener = new YourListener();
try {
  $parser = new \JsonStreamingParser\Parser($stream, $listener);
  $parser->parse();
  fclose($stream);
} catch (Exception $e) {
  fclose($stream);
  throw $e;
}

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.

Projects using this library

JSON Collection Parser

License

MIT License (c) Salsify, Inc.

jsonstreamingparser's People

Contributors

artemprof avatar dennishuckabee avatar dfreeman avatar evulse avatar gonzofy avatar jchamberlain avatar jorissteyn avatar jredburn avatar kolyunya avatar krchiper avatar magomogo avatar maxakawizard avatar mdibbets avatar onkeltem avatar phaza avatar sasezaki avatar thepanz avatar vearutop avatar wohlie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.