I'm developing a system in which a C coded TCP server is listening for new connections from clients, on connection parse the data & store into database.

I'm familiar with JSON, and would like to use this as the data-interexchange between client & server. My issue here is the additional complexity of parsing json using C, in context to using a dynamic language such as php or java.

Before i start venturing in JSON headers/libraries (i'm currently looking at json-c), i thought it best to check with the community if JSON was a reasonable choice of format for this purpose? I've only worked with data inter-exchanges with higher level languages, so ease of parsing was always taken for granted.

3 Answers 3


Parsing chunks from a stream is usually an issue.

One of the issues is that you often need to know the size of the packet to allocate the buffer needed to hold it while parsing. Most text based formats don't have that instead they are delimited by a special set of characters (JSON it's the closing brace/bracket).

If you elect for a binary transmission I suggest a fixed header with size and a integer denoting what message it is.


Don't see why not, its juts another format you have to handle, and there are thousands of them in the wild already. At least JSON is a well-known format.

A quick google says libjso, cJSON, and NxJSON are available as libraries to help parse and manage your data payloads so there shouldn't be much issue with the complexity of parsing it, no ore so than XML or text, say.

One thing I would suggest is to use an embedded webserver instead of a plain socket, if you're using JSON I might guess you may want web clients in the future (as there are plenty of these to chose from and they're really simple to add to your project)


There are also some other libraries used for data exchange, e.g. protobuf or MessagePack. These libraries can better fit your needs - depends on data you plan to exchange

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.