https://github.com/marcpage/yajson
Yet another JSON library lightweight C++ header
https://github.com/marcpage/yajson
c-plus-plus c-plus-plus-11 cplusplus cpp cross-platform header-only json json-parser json-serialization rfc-6901 rfc-7158 rfc-7159 rfc-8259
Last synced: 27 days ago
JSON representation
Yet another JSON library lightweight C++ header
- Host: GitHub
- URL: https://github.com/marcpage/yajson
- Owner: marcpage
- License: unlicense
- Created: 2025-02-26T12:19:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-29T13:16:45.000Z (about 1 year ago)
- Last Synced: 2025-04-29T14:31:48.627Z (about 1 year ago)
- Topics: c-plus-plus, c-plus-plus-11, cplusplus, cpp, cross-platform, header-only, json, json-parser, json-serialization, rfc-6901, rfc-7158, rfc-7159, rfc-8259
- Language: C++
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yajson


[](https://github.com/marcpage/yajson/commits)
[](https://github.com/marcpage/yajson/commits)

[](https://github.com/marcpage/yajson)
[](https://github.com/marcpage/yajson/issues)
[](https://github.com/marcpage?tab=followers)
[](https://github.com/marcpage/yajson/watchers)
Yet Another JSON: C++ light-weight JSON parser and formatter
## Features
- Single header file, less than 1,500 lines of code
- Supports C++11 and later
- Pure C++: supports Linux, macOS, and Windows
- Supports full [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259) compliance
- With the exception of adopting ECMAScript 6's `\u{XXXXXX}` unicode support
- Only generated when Unicode is outside of the supported range for RFC 8259
- Always allowed in parsing
- Uses dictionary and array semantics as well as methods
- Can create via parsing text or programatically
- Compact or human-readable text formatting available
- Over 90% unit test code coverage
## Example Usage
```C++
#include "yajson/yajson.h"
#include
int main() {
auto json = R"(
{
"test\"me\"": [
1,
2.0,
{"go\/now":3},
{"eol": "\r\n"},
{"ht": "\t"},
{"vt": "\f", "bell": "\b"},
true,
false,
null,
"C:\\"
]
}
)";
auto object = yajson::Value::parse(json);
object["key"] = yajson::Value::object()
.set("real", 3.14)
.set("integer", 42)
.set("null", yajson::Value::null())
.set("list", yajson::Value::array()
.append("JSON Rocks")
.append(true));
std::cout << object.format() << std::endl;
std::cout << std::endl << object.format(2);
return 0;
}
```
Which produces:
```json
{"key":{"integer":42,"list":["JSON Rocks",true],"null":null,"real":3.140000},"test\"me\"":[1,2.000000,{"go\/now":3},{"eol":"\r\n"},{"ht":"\t"},{"bell":"\b","vt":"\f"},true,false,null,"C:\\"]}
{
"key":{
"integer":42,
"list":[
"JSON Rocks",
true
],
"null":null,
"real":3.140000
},
"test\"me\"":[
1,
2.000000,
{
"go\/now":3
},
{
"eol":"\r\n"
},
{
"ht":"\t"
},
{
"bell":"\b",
"vt":"\f"
},
true,
false,
null,
"C:\\"
]
}
```