https://github.com/nomango/configor
A light weight configuration library for C++
https://github.com/nomango/configor
configuration cpp json
Last synced: 18 days ago
JSON representation
A light weight configuration library for C++
- Host: GitHub
- URL: https://github.com/nomango/configor
- Owner: Nomango
- License: mit
- Created: 2019-04-11T08:08:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T07:51:50.000Z (11 months ago)
- Last Synced: 2025-03-28T14:07:55.641Z (25 days ago)
- Topics: configuration, cpp, json
- Language: C++
- Homepage:
- Size: 690 KB
- Stars: 593
- Watchers: 11
- Forks: 69
- Open Issues: 4
-
Metadata Files:
- Readme: README-zh.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://open.vscode.dev/Nomango/configor)
[](https://github.com/Nomango/configor/actions)
[](https://www.codacy.com/gh/Nomango/configor/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Nomango/configor&utm_campaign=Badge_Grade)
[](https://codecov.io/gh/Nomango/configor)
[](https://github.com/Nomango/configor/releases/latest)
[](https://github.com/Nomango/configor/blob/master/LICENSE)为 C++11 设计的轻量级配置库
[EN](./README.md) | [中文](./README-zh.md)
## 特点
- 仅头文件,低接入成本
- STL-like,低学习成本
- 自定义类型转换与序列化
- 完备的 Unicode 支持
- ASCII & 宽字符支持## 快速上手
创建 JSON 文档对象
```cpp
json::value j;
j["integer"] = 1;
j["float"] = 1.5;
j["string"] = "something";
j["boolean"] = true;
j["user"]["id"] = 10;
j["user"]["name"] = "Nomango";json::value j2 = json::object{
{ "null", nullptr },
{ "integer", 1 },
{ "float", 1.3 },
{ "boolean", true },
{ "string", "something" },
{ "array", json::array{ 1, 2 } },
{ "object", json::object{
{ "key", "value" },
{ "key2", "value2" },
}},
};
```类型转换 & 序列化:
```cpp
struct User
{
std::string name;
int age;// 将自定义类型绑定到 configor
CONFIGOR_BIND(json::value, User, REQUIRED(name), OPTIONAL(age))
};// User -> json
json::value j = User{"John", 18};
// json -> User
User u = json::object{{"name", "John"}, {"age", 18}};// User -> string
std::string str = json::dump(User{"John", 18});
// string -> User
User u = json::parse("{\"name\": \"John\", \"age\": 18}");// User -> stream
std::cout << json::wrap(User{"John", 18});
// stream -> User
User u;
std::cin >> json::wrap(u);
```更多内容请到 [wiki](https://github.com/Nomango/configor/wiki) 查看。
## Star History
[](https://star-history.com/#nomango/configor&Date)
## 计划
- [x] 自定义类型转换
- [x] Unicode 支持
- [x] 单元测试覆盖率达到 85%
- [ ] 完善错误信息
- [ ] YAML 支持
- [ ] ini 支持
- [ ] json5 支持
- [ ] SAX 工具