Giter VIP home page Giter VIP logo

jsonparser's Introduction

Description

This is a PHP implementation of an event based JSON parser.

The idea of implementing this arose when I needed to parse very large JSON files. PHP having only json_decode, would choke and utterly die when dealing with 100's of MBs worth of JSON.

It is designed to be light-weight and does its job well enough for me to be ready to release it.

Code

The final code, if you're looking for it is located in the package folder.

The src folder actually contains the code for the lexer (it needs to be compiled into a PHP lexer via JLexPHP). This also explains why the generated Lexer is a bit tough on the eyes.

If you desire to rework and experiment with the lexer, you're welcome to and can make use of the makefile to rebuild it.

How

Read the test/test.php file for a real example. But basically:

  • create a parser instance
  • set the handlers for the events you're interested in
  • run the parseDocument method
  • wait 'n see

Implementation choices

I first worked on this using lemon-php as parser. The problem with that is lemon would wait until an element had been fully matched before actually triggering an action.

Of course, it would be very inconvenient since you would only get a notification for the top object once the full document got parsed.

I therefore decided to roll my own parser. JSON has a very straight forward syntax and little room for crazyness, so a dumbed down LL custom made parser does just fine.

jsonparser's People

Contributors

kuma-giyomu 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.