Coder Social home page Coder Social logo

php-jzon's Introduction

PHP JZON

This is a small PHP library for parsing JZON documents.

This library has a pure PHP implementation and a much faster C version implemented as an extension. If the C extension is missing it gracefully fallbacks to the PHP implementation.

What is JZON?

JZON is a superset of JSON which is designed to be actively edited by humans.

PHP JZON features:

  • no need to worry about trailing commas

  • one line comments starting with #

  • simple array keys don't need to be quoted with ""

  • parsing errors are shown in a friendly manner

Quick Example

Say, you have the following JZON file example.json:

#!json

["foo",
  "bar",
 {meaning_of_life: 42,
#NOTE: no comma ahead
#      and yes comments are supported!
   hey: "bar"
  "thatscool": 1
  }
]

Now you can parse it this way:

#!php

<?php
include('jzon.inc.php');
$str = file_get_contents('example.json');
var_dump(jzon_parse($str));

And it should output something as follows:

array(3) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
  [2]=>
  array(3) {
    ["thatscool"]=>
    int(1)
    ["meaning_of_life"]=>
    int(42)
    ["hey"]=>
    string(3) "bar"
  }
}

How do I get set up?

PHP only version

  • Clone the repo

  • Include jzon.inc.php and use jzon_parse($str) function

C extension(recommended)

  • Clone the repo

  • Follow the standard PHP extension installation procedure: phpize && ./configure && make && make install

  • Add "extension=jzon.so" line to your php.ini

  • Include jzon.inc.php and use jzon_parse($str) function

Credits

C extension is based on a bit modified code from https://github.com/KarlZylinski/jzon-c repository.

php-jzon's People

Contributors

pachanga avatar

Watchers

 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.