{"id":13418154,"url":"https://github.com/kazuho/picojson","last_synced_at":"2025-05-15T20:05:11.327Z","repository":{"id":1369334,"uuid":"1319936","full_name":"kazuho/picojson","owner":"kazuho","description":"a header-file-only, JSON parser serializer in C++","archived":false,"fork":false,"pushed_at":"2024-07-13T08:02:44.000Z","size":211,"stargazers_count":1129,"open_issues_count":60,"forks_count":222,"subscribers_count":65,"default_branch":"master","last_synced_at":"2025-04-08T01:38:57.208Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kazuho.png","metadata":{"files":{"readme":"README.mkdn","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-02-02T10:37:03.000Z","updated_at":"2025-03-28T10:40:06.000Z","dependencies_parsed_at":"2024-05-01T23:11:56.084Z","dependency_job_id":"fb342287-5be6-4273-aa2a-e7f2570467a0","html_url":"https://github.com/kazuho/picojson","commit_stats":{"total_commits":167,"total_committers":30,"mean_commits":5.566666666666666,"dds":0.4610778443113772,"last_synced_commit":"111c9be5188f7350c2eac9ddaedd8cca3d7bf394"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuho%2Fpicojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuho%2Fpicojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuho%2Fpicojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazuho%2Fpicojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazuho","download_url":"https://codeload.github.com/kazuho/picojson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414499,"owners_count":22067272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:00:59.061Z","updated_at":"2025-05-15T20:05:04.627Z","avatar_url":"https://github.com/kazuho.png","language":"C++","funding_links":[],"categories":["TODO scan for Android support in followings","JSON","C/C++","进程间通信","Data Formats","C++"],"sub_categories":["JSON","Json"],"readme":"# PicoJSON - a C++ JSON parser / serializer\n\nCopyright \u0026copy; 2009-2010 Cybozu Labs, Inc.\nCopyright \u0026copy; 2011-2015 Kazuho Oku\n\nLicensed under [2-clause BSD license](http://opensource.org/licenses/BSD-2-Clause)\n\n## Version\n\n1.3.1-dev [![Build Status](https://travis-ci.org/kazuho/picojson.svg?branch=master)](https://travis-ci.org/kazuho/picojson)\n\n## Introduction\n\nPicoJSON is a tiny JSON parser / serializer for C++ with following properties:\n\n- header-file only\n- no external dependencies (only uses standard C++ libraries)\n- STL-frendly (arrays are represented by using std::vector, objects are std::map)\n- provides both pull interface and streaming (event-based) interface\n\n## Reading JSON using the pull interface\n\nThere are several ways to use the pull (DOM-like) interface of picojson.\n\nThe easiest way is to use the two-argument `parse` function.\n\n```\nstd::string json = \"[ \\\"hello JSON\\\" ]\";\npicojson::value v;\nstd::string err = picojson::parse(v, json);\nif (! err.empty()) {\n  std:cerr \u003c\u003c err \u003c\u003c std::endl;\n}\n```\n\nFour-argument `parse` function accepts a pair of iterators, and returns the end position of the input.\n\n```\nconst char* json = \"{\\\"a\\\":1}\";\npicojson::value v;\nstd::string err;\nconst char* json_end = picojson::parse(v, json, json + strlen(json), \u0026err);\nif (! err.empty()) {\n  std::cerr \u003c\u003c err \u003c\u003c std::endl;\n}\n```\n\n```\nstd::istream_iterator input(std::cin);\npicojson::value v;\nstd::string err;\ninput = picojson::parse(v, input, std::istream_iterator(), \u0026err);\nif (! err.empty()) {\n  std::cerr \u003c\u003c err \u003c\u003c std::endl;\n}\n```\n\nIt is also possible to use the `\u003e\u003e` operator to parse the input, however this interface is not thread-safe.\n\n```\npicosjon::value v;\nstd::cin \u003e\u003e v;\nstd::string err = picojson::get_last_error();\n```\n\n## Accessing the values\n\nValues of a JSON object is represented as instances of picojson::value class.\n\n\u003cpre\u003e\nnamespace picojson {\n\n  class value {\n    ...\n\n  public:\n\n    typedef std::vector\u0026lt;value\u0026gt; array;\n    typedef std::map\u0026lt;std::string, value\u0026gt; object;\n\n    value();                               // create a null object\n    explicit value(bool b);                // create a boolean object\n    explicit value(double n);              // create a number object\n    explicit value(const std::string\u0026 s);  // create a string object\n    explicit value(const array\u0026 a);        // create an array object\n    explicit value(const object\u0026 o);       // create an \"object\"\n\n    bool is\u0026lt;picojson::null\u0026gt;() const;       // check if the object is \"null\"\n\n    bool is\u0026lt;bool\u0026gt;() const;                 // check if the object is a boolean\n    const bool\u0026 get\u0026lt;bool\u0026gt;() const;         // const accessor (usable only if the object is a boolean)\n    bool\u0026 get\u0026lt;bool\u0026gt;();                     // non-const accessor (usable only if the object is a boolean)\n\n    bool is\u0026lt;double\u0026gt;() const;               // check if the object is a number\n    const double\u0026 get\u0026lt;double\u0026gt;() const;     // const accessor (usable only if the object is a number)\n    double\u0026 get\u0026lt;double\u0026gt;();                 // non-const accessor (usable only if the object is a number)\n\n    bool is\u0026lt;std::string\u0026gt;() const;          // check if the object is a string\n    const std::string\u0026 get\u0026lt;std::string\u0026gt;() const;\n                                           // const accessor (usable only if the object is a string)\n    std::string\u0026 get\u0026lt;std::string\u0026gt;();       // non-const accessor (usable only if the object is a string)\n\n    bool is\u0026lt;array\u0026gt;() const;                // check if the object is an array\n    const array\u0026 get\u0026lt;array\u0026gt;() const;       // const accessor (usable only if the object is an array)\n    array\u0026 get\u0026lt;array\u0026gt;();                   // non-const accessor (usable only if the object is an array)\n\n    bool is\u0026lt;object\u0026gt;() const;               // check if the object is an \"object\"\n    const object\u0026 get\u0026lt;object\u0026gt;() const;     // const accessor (usable only if the object is an object)\n    object\u0026 get\u0026lt;object\u0026gt;();                 // non-const accessor (usable only if the object is an array)\n\n    bool evaluate_as_boolean() const;      // evaluates the object as a boolean\n\n    std::string serialize() const;         // returns the object in JSON representation\n    template\u003ctypename Iter\u003e void serialize(Iter os) const;\n                                           // serializes the object in JSON representation through an output iterator\n\n    std::string to_str() const;            // returns the object in string (for casual use)\n\n  };\n\n}\n\u003c/pre\u003e\n\nThe code below parses a JSON string and prints the contents of the object.\n\n\u003cpre\u003e\npicojson::value v;\n\n// parse the input\nstd::cin \u0026gt;\u0026gt; v;\nstd::string err = picojson::get_last_error();\nif (! err.empty()) {\n  std::cerr \u0026lt;\u0026lt; err \u0026lt;\u0026lt; std::endl;\n  exit(1);\n}\n\n// check if the type of the value is \"object\"\nif (! v.is\u0026lt;picojson::object\u0026gt;()) {\n  std::cerr \u0026lt;\u0026lt; \"JSON is not an object\" \u0026lt;\u0026lt; std::endl;\n  exit(2);\n}\n\n// obtain a const reference to the map, and print the contents\nconst picojson::value::object\u0026 obj = v.get\u0026lt;picojson::object\u0026gt;();\nfor (picojson::value::object::const_iterator i = obj.begin();\n     i != obj.end();\n     ++i) {\n  std::cout \u0026lt;\u0026lt; i-\u0026gt;first \u0026lt;\u0026lt; ': ' \u0026lt;\u0026lt; i-\u0026gt;second.to_str() \u0026lt;\u0026lt; std::endl;\n}\n\u003c/pre\u003e\n\nPlease note that the type check is mandatory; do not forget to check the type of the object by calling is\u0026lt;type\u0026gt;() before accessing the value by calling get\u0026lt;type\u0026gt;().\n\n## Reading JSON using the streaming (event-driven) interface\n\nPlease refer to the implementation of picojson::default_parse_context and picojson::null_parse_context.  There is also an example (examples/streaming.cc) .\n\n## Serializing to JSON\n\nInstances of the picojson::value class can be serialized in three ways, to ostream, to std::string, or to an output iterator.\n\n\u003cpre\u003e\npicojson::value v;\n...\nstd::cout \u0026lt;\u0026lt; v;\n\u003c/pre\u003e\n\n\u003cpre\u003e\npicojson::value v;\n...\nstd::string json = v.serialize();\n\u003c/pre\u003e\n\n\u003cpre\u003e\npicojson::value v;\n...\nv.serialize(std::ostream_iterator\u0026lt;char\u0026gt;(std::cout));\n\u003c/pre\u003e\n\n## Experimental support for int64_t\n\nExperimental suport for int64_t becomes available if the code is compiled with preprocessor macro `PICOJSON_USE_INT64`.\n\nTurning on the feature will cause following changes to picojson:\n- new constructor `picojson::value(int64_t)` is defined\n- `is\u003cint64_t\u003e()` and `get\u003cint64_t\u003e()` become available\n- numerics in JSON within the bounds of int64_t and not using `.` nor `e`/`E` are considered as int64 type\n - the values are also avaliable as `double`s as well (i.e. all values which are `.is\u003cint64_t\u003e() == true` are also `.is\u003cdouble\u003e() == true`)\n- int64 values are converted to double once `get\u003cdouble\u003e()` is called\n\nEnabling the feature should not cause compatibility problem with code that do not use the feature.\n\n## Further reading\n\nExamples can be found in the \u003ci\u003eexamples\u003c/i\u003e directory, and on the [Wiki](https://github.com/kazuho/picojson/wiki).  Please add your favorite examples to the Wiki.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazuho%2Fpicojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazuho%2Fpicojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazuho%2Fpicojson/lists"}