All Projects → ttsuki → Nanojson

ttsuki / Nanojson

Licence: mit
Single C++ header file only json reader/writer

Labels

Projects that are alternatives of or similar to Nanojson

Himalaya
JavaScript HTML to JSON Parser
Stars: ✭ 758 (+12533.33%)
Mutual labels:  json
Latke
🌀 一款以 JSON 为主的 Java Web 框架。
Stars: ✭ 781 (+12916.67%)
Mutual labels:  json
Gojq
Pure Go implementation of jq
Stars: ✭ 800 (+13233.33%)
Mutual labels:  json
Portabletext
Portable Text is a JSON based rich text specification for modern content editing platforms.
Stars: ✭ 759 (+12550%)
Mutual labels:  json
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+117350%)
Mutual labels:  json
Himotoki
A type-safe JSON decoding library purely written in Swift
Stars: ✭ 786 (+13000%)
Mutual labels:  json
Factbook.json
World Factbook Country Profiles in JSON - Free Open Public Domain Data - No API Key Required ;-)
Stars: ✭ 750 (+12400%)
Mutual labels:  json
Jsonlite
A simple, self-contained, serverless, zero-configuration, json document store.
Stars: ✭ 819 (+13550%)
Mutual labels:  json
Amis
前端低代码框架,通过 JSON 配置就能生成各种页面。
Stars: ✭ 8,930 (+148733.33%)
Mutual labels:  json
Kt
Kafka command line tool that likes JSON
Stars: ✭ 799 (+13216.67%)
Mutual labels:  json
Leetheme
优雅的主题管理库- 一行代码完成多样式切换
Stars: ✭ 762 (+12600%)
Mutual labels:  json
Ason
[DEPRECATED]: Prefer Moshi, Jackson, Gson, or LoganSquare
Stars: ✭ 777 (+12850%)
Mutual labels:  json
Winterfell
Generate complex, validated and extendable JSON-based forms in React.
Stars: ✭ 787 (+13016.67%)
Mutual labels:  json
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+12550%)
Mutual labels:  json
Yaml.js
Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.
Stars: ✭ 810 (+13400%)
Mutual labels:  json
Quicktype
Generate types and converters from JSON, Schema, and GraphQL
Stars: ✭ 7,459 (+124216.67%)
Mutual labels:  json
Droidparts
Stars: ✭ 785 (+12983.33%)
Mutual labels:  json
Bludit
Simple, Fast, Secure, Flat-File CMS
Stars: ✭ 824 (+13633.33%)
Mutual labels:  json
Dyson
Node server for dynamic, fake JSON.
Stars: ✭ 814 (+13466.67%)
Mutual labels:  json
Rss Parser
A lightweight RSS parser, for Node and the browser
Stars: ✭ 793 (+13116.67%)
Mutual labels:  json

nanojson - Simple json reader/writer

🌟 Single C++ header only.

🔴 Caution! this library allows:

  • last comma of array: [1,2,3,]
  • last comma of object: { "a":1, "b":2, }
  • non-quoated object-key: { a:1, b:2 }
  • block/line comment: [ /* value of hoge */ 1, ] // <- array of fuga
    • for the purpose of parsing json-like configuration file with help comment.

License

MIT

Sample Code

#include "nanojson.h"
#include <iostream>

int main()
{
	#define LF "\n"
	std::stringstream ss = std::stringstream(std::string(
		"[123, {"                                    LF
		"a : \"あいう\\\\n\\tえお\", "                 LF
		"  \t b : true, "                            LF
		"     c : null, "                            LF
		" /* start comment ..."                      LF
		"     x : here is in block comment"          LF
		"                  ... end comment */"       LF
		"\"d\\u0001\" : false, "                     LF
		"   // e is a test integer."                 LF
		"   // f is a test floating."                LF
		"e : 1234567890123456789, "                  LF
		"f : -123.4567e+89, "	                     LF
		"}  ]"));

	std::cout << "input json: " << std::endl;
	std::cout << ss.str() << std::endl;

	std::cout << "parsed json:" << std::endl;
	nanojson::element e = nanojson::element::from_string(ss.str());
	std::cout << e.to_json_string() << std::endl;

	std::cout << "values:" << std::endl;
	if (e[1]["a"].is_defined()) { std::cout << "e[1][\"a\"] = " << e[1]["a"].to_string() << std::endl; }
	if (e[1]["f"].is_defined()) { std::cout << "e[1][\"f\"] = " << e[1]["f"].to_string() << std::endl; }
	if (e[1]["x"].is_defined()) { std::cout << "e[1][\"x\"] = " << e[1]["x"].to_string() << std::endl; }
	
	std::cout << "input test json:" << std::endl;
	try {
		std::cin >> e;
	}
	catch (nanojson::nanojson_exception &)
	{
		std::cout << "il-formed json data." << std::endl;
		e = nanojson::element::undefined();
	}
	std::cout << "parsed json:" << std::endl;
	std::cout << e << std::endl;

	return 0;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].