Giter Site home page Giter Site logo

jsonic's Introduction

jsonic

A JSON parser for Node.js that isn't strict.

A JSON parser that can parse "bad" JSON. Mostly, this is about avoiding the need to quote everything!

Strict JSON requires you to do this:

{ "foo":"bar", "red":1 }

The JavaScript language itself is a little easier:

{ foo:"bar", red:1, }

But if you really want to be lazy, jsonic lets you say:

foo:bar, red:1,

See below for the relaxed JSON rules.

This module is used by the Seneca framework to provide an abbreviated command syntax.

Support

If you're using this module, feel free to contact me on twitter if you have any questions! :) @rjrodger

Current Version: 0.1.1

Tested on: node 0.10.19, Chrome 29

Build Status

Quick example

var jsonic = require('jsonic')

// parse a string into a JavaScript object
var obj = jsonic('foo:1, bar:zed')

// prints { foo: '1', bar: 'zed' }
console.dir( obj )

Install

npm install jsonic

Relaxed Rules

JSONIC format is just standard JSON, with a few rule relaxations:

  • You don't need to quote property names: { foo:"bar baz", red:255 }
  • You don't need the top level braces: foo:"bar baz", red:255
  • You don't need to quote strings with spaces: foo:bar baz, red:255
  • You do need to quote strings if they contain a comma or closing brace: icky:",}_"
  • You can use single quotes for strings: Jules:'Cry "Havoc," and let slip the dogs of war!'
  • You can have trailing commas: foo:bar, red:255,

How it Works

The parser uses PEG.js and is an extension of the example JSON parser included in that project.

Development

You'll need:

sudo npm install [email protected] uglify-js -g

jsonic's People

Contributors

rjrodger 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.