vivkin / gason

Lightweight and fast JSON parser for C++
MIT License
338 stars 51 forks source link

added json writing support #39

Closed tuket closed 2 years ago

tuket commented 2 years ago

Hello,

This PR adds a couple of files "json_write.h" and "json_write.cpp" with a single API function:

// Returns the number of characters that are written to the buffer (including the null character)
// You can call this function with buffer=nullptr to query the memory you need to allocate
// If your buffer is not big enough, the function writes until runs out of space,
//      and returns the number of characters that would have been written if the buffer was big enough
size_t jsonWrite(const JsonValue& val, size_t bufferSize, char* buffer, char* indentor = "\t"); 

I added a small test to the test suite.

Since I worked with VisualStudio I also added support for it in the CMake (I had to update the CMake version to use the new CMAKE_CXX_STANDARD config variable).

Thanks!

tuket commented 2 years ago

I realized that, for this to be useful, more work is needed. The current JsonValue API doesn't allow to build a hierarchy easily.