Coder Social home page Coder Social logo

okjson's Introduction

This is a json parser, written in ruby.
It has no dependencies other than ruby.
See the file tested-on for a complete list
of ruby interpreters used for testing.


To Use:

  OkJson.encode({"abc" => [123, -456.789]})
  => "{\"abc\":[123,-456.789]}"

  OkJson.decode('{"abc":[123,-456.789e0]}')
  => {"abc"=>[123, -456.789]}

That's it.


This library is intended to be "vendored".
It is not a gem; instead, copy okjson.rb
into your project and "require" it directly.
This method helps you avoid an external
dependency. It's only about 575 lines of
source; about half of that is UTF-8 coding.
If you bundle okjson with your library,
please change the module's name to something
like MyLib::OkJson, to avoid conflicts with
other libraries.

OkJson is not particularly fast or flexible,
but it is designed to be simple and portable.
It should suffice for most needs.

It provides two guarantees:
 1. okjson will never generate invalid json
 2. OkJson.decode(OkJson.encode(x)) == x

Note for people who've used other ruby json
libraries: json does not represent symbols,
so okjson does not encode them. It won't
convert them to strings; that would silently
corrupt your data. The same holds for all of
ruby's other data types that don't exist in
json, including Range, Regexp, Proc, Time,
and user-defined classes.

Patches to increase the correctness,
readability, or portability of the
source code will be gratefully accepted.
Other patches (for example, extra features
or optional behavior) likely won't.


To Test:

  $ ./rubies ruby rbx /opt/ruby192/bin/ruby

(Note: these tests originated at
https://github.com/genki/json
but have been changed to follow
RFC 4627 and revised substantially.)

okjson's People

Contributors

ddollar avatar kr avatar sferik 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.