Loading...
JSON++ :: About
A C++ JSON parser. The difference between this Parser and others, (jsoncpp. | zoolib.) is that it is designed to be permissive rather than restrictive. It is also designed to work well with the ECMA standard rather than the formal JSON format. This increases compatibility with JavaScript. Also, compilation does not rely on any stange make-tools. A makefile, and Visual Studio Project file are included.
Features:
- Accepts Single ( //) and Multi-line Comments (/* hi */ )
- Allows unquoted names ( { hello : "world" } )
- Internally uses all Unicode strings
- Built-in UTF-8 conversions
- No external dependencies (Apart from a modern C++ stdlib) or build requirements
Potential Issues:
- Documentation. The json::value class definition is pretty self-explanatory, but all documentation is below.
- Values added to an object are always inserted according to alphabetical precedence:
{c:1, a:2, b:3}
becomes
{a:2, b:3, c:1}
Performance
The library should perform more then well enough for day-to-day usage. A simple speed test using a 52.6Mb complex Json file containing 3,971,363 values takes 6 seconds to load,parse, and iterate over, using Windows Mmapping on an dual core Athlon 2Ghz machine. Total memory usage was around 108 Mb. There is room for major improvements in the code performance.
JSON++ :: Example
Example Usage:
#include <iostream>
#include <string>
#include "json/parser.h"
using namespace std;
int main(int argc, wchar_t* argv[])
{
char *json_string="{ hello : \"World\", \"number\": 1}";
json::parser myparser;
json::value *myvalue=myparser.parse(json_string,strlen(json_string));
myvalue->addobjectvalue(L"Boolean",new json::value(true));
wstring *out_string=myvalue->getstring(L"",true);
wcout<<L"Output:"<<(out_string->c_str())<<endl;
delete out_string;
delete myvalue;
cin.get();
return 0;
}
Should output:
Output: { "Boolean" : true , "hello" : "World" , "number" : 1 }