百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

simpleson

> 编程语言
开源

一个轻量级的 C++ JSON 解析器和序列化器,兼容 C++98,无依赖性

99 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个轻量级的 C++ JSON 解析器和序列化器,兼容 C++98,无依赖性

Linux / Windows / macOS ESP

simpleson

Lightweight C++ JSON parser & serializer that is C++98 compatible with no dependencies

Github Repository

Documentation

Why simpleson?

Simpleson is built under the following requirements:

  • One header and one source file only
  • No external dependencies
  • ISO/IEC 14882:1998 (aka C++98) compatible
  • Cross-platform

A primary use case for simpleson is in an memory-constrained embedded system.

Building simpleson

Simpleson was intentionally built such that a developer could simply copy json.h into the target project's inc folder, copy json.cpp into the src folder, and then compile the target project. No linking -> no drama.

Building the library and tests follows the standard build chain via CMake:

bash
mkdir build
cd build
cmake ../
make

Unit tests can then be run by executing make test

Quickstart

…

Using simpleson

The namespace of simpleson is simply json. JSON objects can be parsed by calling json::jobject::parse(), which takes a string and returns a jobject. The array operators are overloaded for jobject, meaning you can assign and access entries using the [] operators like many other software languages. Other useful methods of jobject include:

  • has_key("key") - Returns true if the key exists in the jobject
  • remove("key") - Removes they entry associated with the key if the key exists in the jobject
  • clear() - Removes all entries in the jobject
  • ["key"].set_boolean(true) - Sets the key to the boolean value
  • ["key"].set_null() - Sets the value associated with the key to null
  • ["key"].is_true() - Returns true if the boolean value associated with the key is true
  • ["key"].is_null() - Returns true if the value associated with the key is null
  • pretty() - Serializes the object into a "pretty" string (using tabs and newlines)

An instance of jobject can be searlized by casting it to a std::string. Note that an instance of jobject does not retain it's original formatting (it drops tabs, spaces outside strings, and newlines).

Arrays

Simpleson supports arrays as the root object:

cpp
json::jobject example = json::jobject::parse("[1,2,3]");
int one = example[0]; // Value is 1
int two = example[1]; // Value is 2
int three = example[2]; // Value is 3

Arrays are stored in a jobject. You can determine whether a jobject is holding an array through the method is_array().

Multi-level Access

To access elements several levels down, the get(key) and array(index) can be used for objects and arrays, respectively:

cpp
std::string music_desired = example.array(0).get("hobbies").array(1).get("music");

See the full example here.

A note on booleans

Booleans are handled a bit differently than other data types. Since everything can be cast to a boolean, having an implicit boolean operator meant everything goes to a boolean! Instead, boolean values are set by using the set_boolean() method. If you do not use this method and instead directly create/assign a boolean to a jobject array entry, then the boolean will be cast to an int with a value of 0 or 1. Similarly, you can check if a value is set to true or false using the is_true() method.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++c-plus-pluscpluspluscppesp32

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言