Giter Club home page Giter Club logo

jsonparser's Introduction

JsonParser for C++

This project is a full-fledged JSON parser that is capable of parsing any .json file following the RFC4627 standard into an easily traversable C++ data structure.

How to use

  1. Parse a JSON file.
auto parser = new Json::Parser();
auto json = parser.parse("path_to_json");
  1. Traverse the returned JSON structure
auto node = json->at("users")->at(0)->at("age");
  1. Convert node to value
int age = node->getAs<int>();
  1. Iterate through a list or an object
for (auto user : json->at("users"))
{
	std::string userName = user->at("name")->getAs<std::string>();
}

Notes

  • The getAs<T>() method only accepts types that can be stored in a JSON node, such types are: bool, int, double, std::string, std::nullptr_t, Json::List and Json::Object.
  • Json::List and Json::Object hide an std::vector and an std::map of Json::Node shared pointers respectively.
  • Trying to perform an unsupported conversion using the getAs<T>() function (i.e the user tries to convert a string node to int) throws an exception.
  • Trying to use the at(int) function on a non-list node, as well as trying to use the at(std::string) function on a non-object node throws an expression.
  • The parser will throw an exception if the JSON object found in the provided .json file contains serious formatting errors.

jsonparser's People

Contributors

levente-varga 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.