A JSON string parser by C++
There are two part in this presentation:
All of the source codes are in the src directory, and there are 2 C++ header file and a C++ source code file:
- colors.hpp: In this file, we defined some color string literal of ANSI Escape Character of Colors likes:
#define RED "\033[91m"
#define GREEN "\033[92m"
// And there are some other definitions.- json.hpp: The core of this project, we will have a more detailed understanding after (it will may have some introuce later on TxT).
- main.cpp: It is approximately an example program, but now, we use it for test our code usually, so if you want to get a program that it can run, don't compile this file now; and you need to read our source code and write a another file to run it; but maybe you don't want to read these source code so long, so we'll write some using documents later.We will write some example program at the begin of 2026 November.
If you have good program, you can tell us by PR of Issues!
On the 2026/10/17, it's:
The great mass of codes are in the namespace "json":
And the data structures are all in the namespace "DataTypes":
Every data structure is extended from class DataBase; And there are 6 data structures:
- String
- Number
- Boolean
- Array
- Object
- Null
And both the class JsonParsingException and the class Parser are in the namespace json too:
- JsonParsingException: When the Parser processing and it makes error, use JsonParsingException to throw error with message and more infomation
- Parser: Parse json strings to trees
git clone https://github.com/Preversons/JSON.git(If you didn't make build directory)
mkdir buildCompile the source file if you want to run it:
g++ src/main.cpp -o build/main.exeIf you just need to use the header file: Add it in your cpp code file at the begin:
#include "json.hpp" // the json.hpp is in the src directoryIf you need to use Pre-compile:
g++ src/json.hpp -o YOUR_SOURCE_CODE_PATH/json.hpp.gchNote: The author is Chinese and he isn't good at English.If you find some mistake, welcome to tell us and we'll listen and correct it.