Code Monkey home page Code Monkey logo

js0n's Introduction

js0n - Flexible Zero-Footprint JSON Parser in C

A one-pass minimal overhead walk of the raw bytes, using each one as an index into a jump table to determine state transitions.

  • public domain or MIT license, single js0n.c file with one function
  • easy to use, just returns a given key-value pair location in the JSON string
  • no dependencies, embedded friendly
  • requires no memory/malloc or copying, uses only what is passed in (up to int max length)
  • more flexible than strict JSON and allows bare keys (non-validating)
  • optimized for high speed scanning/routing of small chunks of json, stops parsing upon match
  • safely errors on anything really bad (binary, NULLs, etc)

Parsing this:

{
    "barbar": [
        1,
        2,
        3
    ],
    "foo": "bar",
    "obj": {
        "a": "b"
    }
}

Using val = js0n("barbar", 6, json, strlen(json), &vlen) would return a val pointing to [1,2,3] and set vlen to 7.

For arrays, pass NULL as the key, and the array offset as the second argument.

When the value is not found NULL is returned, if there were any parsing errors then vlen will be set to -1.

To determine if the returned value is an actual JSON string or a bare value (like "true" vs true), simply check if it starts with a quote character via if(val && *(val-1) == '"').

For more usage examples see the test.json and test.c.

History

See v1.0 for the original js0n function that returned an index of offsets for all key/values in one pass.

js0n's People

Contributors

catap avatar hildjj avatar matthijskooijman avatar mbucc avatar quartzjer avatar wonder-mice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js0n's Issues

Dual-license with more mature license

The Unlicense is known among software lawyers for being a bit sketchy. Large companies are advised by their lawyers that they can't afford to take Unlicensed software seriously. This is a big shame, because the Unlicense stands for something very significant and we should take strides to improve its legal status, but in the meantime, one could do with a workaround. I suggest the MIT license be used.

LICENSE.txt

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.