Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amir-s/jute
Very simple C++ JSON Parser
https://github.com/amir-s/jute
Last synced: about 2 months ago
JSON representation
Very simple C++ JSON Parser
- Host: GitHub
- URL: https://github.com/amir-s/jute
- Owner: amir-s
- Created: 2013-03-24T16:57:44.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2021-06-17T15:20:56.000Z (about 3 years ago)
- Last Synced: 2024-04-11T19:19:31.615Z (2 months ago)
- Language: C++
- Size: 20.5 KB
- Stars: 70
- Watchers: 7
- Forks: 26
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Lists
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- fucking-awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp-completed - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp-completed - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - 非常简单的C++ JSON解析器. [PublicDomain] (JSON)
- awesome-cpp-cn - jute
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
- awesome-cpp - jute - Very simple C++ JSON Parser. [PublicDomain] (JSON)
README
Very simple JSON parser for c++
data.json:
```JSON
{
"examples": [
{
"tag_name": "a",
"attr": [
{
"key": "href",
"value": "http://amir.saboury.net"
},
{
"key": "target",
"value": "_blank"
}
]
},
{
"this_is": [
"array",
"of",
"strings"
],
"number_array": [
1,
2,
4,
8,
16
],
"pie": 3.14,
"boolean": true,
"bug": null,
"mixed": [
1,
2,
{
"test1": -1.2345,
"test2": false
},
null,
0.4,
[
"nested",
[
"array",
true
]
],
"end of story!"
]
},
{
"done": true
}
]
}
```
example "main.cpp" file
```C++
#include
#include
#include
#include
#include
#include
#include
#include "jute.h"
using namespace std;int main () {
ifstream in("data.json");
string str = "";
string tmp;
while (getline(in, tmp)) str += tmp;
jute::jValue v = jute::parser::parse(str);
cout << v.to_string() << endl;
cout << " ------ " << endl;
cout << v["examples"][0]["attr"][0]["value"].as_string() << endl;
if (v["examples"][1]["mixed"][5][1][1].as_bool()) {
cout << v["examples"][1]["pie"].as_double() << endl;
cout << v["examples"][2].to_string() << endl;
}
// You can get type of a jValue by calling its get_type() function
// It returns a jType which can be one of these:
// {JSTRING, JOBJECT, JARRAY, JBOOLEAN, JNUMBER, JNULL, JUNKNOWN}
//
// if (v["examples"][1]["mixed"][5][1][1].get_type() == jute::JBOOLEAN) ...
return 0;
}```
Note:
This version is not providing error checking. All functions assume the input string is in valid format of JSON. Also number format checking is poor.
Improvements are welcome. Read the source code; it is just about 300 LOC :smile:License: [MIT](https://opensource.org/licenses/MIT)
======