Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Little-Ki/tiny-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

tiny-json

A very simple json parser;

NOTE: Require utf-8 input format.

usage

void demo() {
  auto json_text = R"(
    {
      "string": "hello",
      "int": 100,
      "double": 1.00e1,
      "null": null,
      "ok": true,
      "no": false,
      "array": [
        {
          "inner": "world"
        },
        123.456
      ]
    }
  )";
  json::parser jp(json_text);
  auto success = jp.parse();
  if (success) {
    auto doc = jp.document();
    std::cout << doc["string"].as<std::string>() << '\n';
    std::cout << doc["int"].as<int>() << '\n';
    std::cout << doc["double"].as<double>() << '\n';
    std::cout << doc["null"].is_null() << '\n';
    std::cout << doc["ok"].as<bool>() << '\n';
    std::cout << doc["no"].as<bool>() << '\n';
    std::cout << doc["array"][0]["inner"].as<std::string>() << '\n';
    std::cout << doc["array"][1].as<double>() << '\n';
  }
}
void demo() {
  json::value doc;
  doc = { { "hello", "world" }, { "number", 1234.5f } };
  std::cout << doc["hello"].as<std::string>() << '\n';
  std::cout << doc["number"].as<float>() << '\n';
}
void demo() {
  json::value doc;
  doc = { 123, 456, 789 };
  std::cout << doc[0].as<int>() << '\n';
  std::cout << doc[1].as<int>() << '\n';
}

About

A very simple json parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages