Naroju Naroju -5 years ago 215
JSON Question

Valid json check in C language

I have searched a lot in google, I want to programatically check if the string below is valid json in C.How to do that? I am currently using json-c library.

char * string = "{
number1 : 100,
number2 : 10,
files : [ c , c++, java,PHP,java,PHP ],
random: [123567876523333,908,988]

the library has no function to check if the string is valid json. Thanks in Advance.

Answer Source

You can use the function json_tokener_parse(const char *str), it returns NULL if parsing fails.

See here for details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download