Re: JSON generation in C/C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 1 Aug 2011, Tommi Virtanen wrote:
> We've talked about generating/parsing JSON a few times, and how we've
> run into edge cases whenever we've rolled our own functions for that.
> I've mentioned this C library a few times, but I'm not sure if I've
> actually sent the link to anyone.. Here's a C library for
> generating/parsing JSON, written by an ex-cow-orker of mine.

Heh, you forgot the link again?  :)
 
> One feedback I've received earlier was that the "DOM-style"
> architecture, where you build up the JSON object in-memory and then
> dump it out, is not always a good match. If you want to avoid that,
> you can pull off a trick like this pseudocode:
> 
> write("{")
> json.dump(key)
> write(":")
> json.dump(value)
> write(",")
> json.dump(key2)
> write(":")
> json.dump(value2)
> write("}")
> 
> The above still uses the library for proper string encoding etc, while
> letting you control the top-level structure explicitly. And it should
> be pretty easy to encapsulate the above in a convenience wrapper, to
> make streaming even nicer; something like this pseudocode:
> 
> j = StreamingJSONObject(fd)
> j.dump(key, value)
> j.dump(key2, value2)
> j.close()

That's basically what JSONFormatter is doing, except it has some higher 
level methods for opening object vs array sections, and can add whitespace 
for human readability.  The only thing we'd be using here is the string 
quoting.  It's probably easier to just lift that method than link in an 
external dependency for that.  Or, fix any bugs in the current escaping...

sage
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux