ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.04k stars 262 forks source link

Is there any way to make yyjson api more friendly and easy to use? #81

Closed 77h2l closed 2 years ago

77h2l commented 2 years ago

Hi,all: Is there any way to make yyjson easily to use for serialization and deserialization, for example, can i get the info like nlohmann json or through python-style rather than through the complex parsing ways. Or how can I rewrite it, Thx.

ibireme commented 2 years ago

This library is written in C, not C++.

For example (nlohmann):

j["name"] = "Niels";
j["answer"]["everything"] = 42;

nlohmann overloads the subscript operator, so you can use subscripts to access json, but you can't do that in C.

If your project is in C++, you could write some C++ wrapper functions for yyjson to simplify your code.

sunpengfei0307 commented 2 years ago

I try to write a simple c dict(class like) map to yyjson or other json parsers, so I can use it like python/c++, dict.loads() or dict.dumps(), can handle the read/write things.

`// classlike interface. CLASS(IDict) { // other crud apis. // json string need free by caller.

char*  (*encode)(IDict *_this, const char* path); //dump obj to json(s|f). 
bool   (*decode)(IDict *_this, const char* json); //load json(s|f) to obj. 

}`

yosh-matsuda commented 1 year ago

I wrote an intuitive C++ wrapper that also inherits the great performance of yyjson.

https://github.com/yosh-matsuda/cpp-yyjson

I hope this helps C++ people and the wider use of yyjson.