GithubHelp home page GithubHelp logo

cyjson's Introduction

cyjson

Fast and efficient JSON Parser for Python.

This is a wrapper class written in Cython. The Underlaying library is cJSON by Dave Gamble written in C.

import cyj

parser = cyj.cyj()

#loading data into cyjson and parsing it internally
#returns True on success and False on failure
parser << '{"ab":"test","c":[1,2,{"x":["y","f","w",[6,7,8,10]]},4],"s":{"y":["llüöll",1,false,true]}}'

#information such as types, keywords and item size
print parser.root_info()

#getting information on elements, raises cyJSON_* exception on error
print parser >> ('c',2)

#converting items into python objects
for i in parser.root_info()["keys"]:
	print parser( ( str(i), ) )

loading

parser << "JSON" # will be converted -> .replace("\'","\"")

converting to python object

This is not efficient, because it converts the whole structure into python objects.

parser.get_root()

retrieving info

Instead of converting to python object, we can collect some information and extract the target value directly from C layer which is faster and more efficient.

>>> parser.root_info()
{'keys': [u'ab', u'c', u's'], 'types': ['str', 'list', 'dict'], 'size': 3}
>>> parser >> ('c',)
{'keys': [], 'types': ['num', 'num', 'dict', 'num'], 'size': 4}

get value

>>> parser( ('c',1) )
2
>>> parser( ('c',2 ) )
{'x': [u'y', u'f', u'w', [6, 7, 8, 10]]}

#install git clone --recursive https://github.com/mitghi/cyjson/ cd ./cyjson/cJSON; make ; make install ; cd .. python setup.py build_ext --inplace

#requirements Cython 0.23

cyjson's People

Contributors

mitghi avatar 0x7fff5238100b avatar lucaswiman 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.