Reputation: 1970
I have seen a number of libs for parsing JSON in C but none of them can read and parse directly from file streams. The problem with all such libs e.g Yajl, cjson is that if the json document in the file is huge then you have to first read all of that into a memory buffer and then run the APIs provided by these libs to parse it.
There APIs often look like
cJSON *cJSON_Parse(const char *value)
which take a char* to a buffer.
I want to avoid that since my files can be very large and i donot know the sizes of the files in advance. Moreover, these libs maintain reference to objects,arrays in the actual buffer to retrieve the values so i cannot free the original buffer.
Is there a JSON parsing lib that can read and parse directly from file streams?
Upvotes: 3
Views: 4498
Reputation: 1970
Mapping the file to the process using mmap() and then simply using the address returned to carry out the char* manipulations makes all of them useful and a good way to solve the problem
Upvotes: 1
Reputation: 36987
http://lloyd.github.com/yajl/ is probably what you are looking for
Upvotes: 3