Minimalist JSON API Library for C
####Include clone this repository in your project folder and include it:
#include "lib4json/lib4json.c"####Documentation
// create json string {"userID":1,"username":"Admin","pass":"Lorem123","name":"Christian Brown","admin":true,"Hobbies":["golf","rubik"]}
const char* json = "{\"userID\":1,\"username\":\"Admin\",\"pass\":\"Lorem123\",\"name\":\"Christian Brown\",\"admin\":true,\"Hobbies\":[\"golf\",\"rubik\"]}";
jsonObject myJson = jsonParse(json); //create json object and parse the string
printJsonParsed(myJson);
/* Output --->
[ Hobbies ]: ["golf","rubik"] (Type: Array)
[ admin ]: true (Type: Boolean)
[ name ]: Christian Brown (Type: String)
[ pass ]: Lorem123 (Type: String)
[ username ]: Admin (Type: String)
[ userID ]: 1 (Type: Number)
*/
//save the keys in array
char** keys = getJsonKeys(myJson);
int i;
for(i = 0 ; i < myJson.size ; i++){
printf("Key: %s\n",keys[i]);
}
/* Output -->
Key: Hobbies
Key: admin
Key: name
Key: pass
Key: username
Key: userID
*/
free(keys);
//save the values in array
char** values = getJsonValues(myJson);
int i;
for(i = 0 ; i < myJson.size ; i++){
printf("Value: %s\n",values[i]);
}
/* Output -->
Value: ["golf","rubik"]
Value: true
Value: Christian Brown
Value: Lorem123
Value: Admin
Value: 1
*/
free(values);