Git Product home page Git Product logo

doomhammer / jsonhandle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from locuststar64/jsonhandle

0.0 3.0 0.0 304 KB

JsonHandle is a very simple JSON interface for C++. Its supports encode and decode from char buffers and STL strings & streams. The typing is a lot like duck typing in JavaScript. Handles tranparently transform between types based on usage. Designed to efficiently use memory and improve performance.

License: MIT License

Shell 0.44% C++ 98.47% Python 1.09%

jsonhandle's Introduction

JsonHandle is a very simple JSON interface for C++. Its supports encode and decode from char buffers and STL strings & streams. The typing is a lot like duck typing in JavaScript. Handles tranparently transform between types based on usage. Designed to efficiently use memory and improve performance.

Intended for use in messaging, streaming support for a continuous stream of objecs is supported.

When used for configuration files, there is an option to save for human readbility or compact for size.

WORKING WITH HANDLES

Arrays: access using [] operator or at() method with numeric index. size() will return the number of entries. Items can be removed using erase() or clear() for all.

   JsonHandle root;
   root[0] = "Thomas";
   root.erase(0); 

Objects: access using [] operator or at() method with char * ot std::string index. If an numeric index is used the value at that index will be returned. The keys can be enumerated using the keys method. size() will return the number of entries. Items can be removed using erase() or clear() for all.

   JsonHandle root;
   root["name"] = "Thomas";
   root.erase("name");

Strings: set using setString() or fetch using stringValue() methods Alternatively use the = operator.

   JsonHandle root;
   root["first"] = "Thomas";
   root["last"].setString("Davis");

   cout << "First name is " << root["name"].stringValuePtr() << endl;

Numbers: set using setLong() or setDouble() and fetch using longValue() and doubleValue() methods. Alternatively use the = operator.

   JsonHandle root;
   root["age"].setLong(14);
   root["rate"].setDouble(0.1234);

   cout << "First age is " << root["age"].longValue() << endl;

Boolean: set using setBoolean() and fetch using booleanValue() Alternatively use the = operator.

   JsonHandle root;
   root["old"].setBoolean(false);

   cout << "First age is " << root["age"].longValue() << endl;

Null: set using setNull() and fetch using isNull()

   JsonHandle root;
   root["enemy"].setNull();

   cout << "First age is " << root["age"].longValue() << endl;

References: are created using the copy contructor. The assignment (=) operator makes a depp copy instead is that is desired.

    JsonHandle A;
    JsonHandle B(A["list"]), C;
    B[0] = (int64_t)0;
    B[1] = (int64_t)1;       // B is [ 0, 1 ], A is {"list": [ 0, 1 ] }
    C[0] = (int64_t)2;
    B = C;                   // B is [ 2 ], A is {"list": [ 2 ] }
    C[0] = (int64_t)3;
    A["list"] = C;           // B is [ 3 ], A is {"list": [ 3 ] }

EXAMPLES

Examples are located in the examples direcory with a Linux Makefile.

  • example1 : file writer
  • example2 : file reader
  • example3 : stream writer
  • example4 : stream reader

BUILDING

JsonHandle.h must be included from source files using the API and hence needs to be in the include path.

Copy src/JsonHandle.cpp src/JsonHandle.h src/_JS0.cpp src/_JS0.h to the build and compile them along with the other source code.

As an alternative, build them into a library and use that:

python waf configure
python waf

jsonhandle's People

Contributors

doomhammer avatar

Watchers

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