sheredom / json.h

🗄️ single header json parser for C and C++
The Unlicense
698 stars 77 forks source link

Way to copy the JSON object #64

Closed graphitemaster closed 3 years ago

graphitemaster commented 5 years ago

This is an excellent library but it lacks one useful feature and that is a way to make a copy of the tree you're working with. It's quite beneficial to want to take a copy of the tree or subtree you index for the purposes of storing and passing it off to other systems. The lifetime management gets quite hairy to the point where you're better off just reference counting the root of the tree every time you take a pointer off it. This should be trivial to support since only one call to malloc is made and you can more or less just memcpy things around, but it would be nice if you just copy the subtree if you're indexing.

sheredom commented 4 years ago

So you basically just want a helper function to start at a given node, and copy everything from that node downwards?

That seems do-able if so.

graphitemaster commented 4 years ago

Yeah