Jack is header-only library for parsing JSON data in C.
#define JACK_IMPLEMENTATION
#include "include/jack.h"
int main() {
char *str = "{\"message\":\"Hello, world!\"}";
Json json = Json_Parse(str);
Json_Print(&json, 4);
return 0;
}
- output
{
"message": "Hello, world!"
}
/*
Will create a new JSON object
*/
Json Json_New();
/*
Will parse a raw C string to JSON object
similar to JavaScript's JSON.parse()
*/
Json Json_Parse(char *str);
/*
Will retrive a key-value pair from JSON object "Json *j"
with key equal to "char *key", returns NULL if not found.
*/
JsonKeyValuePair *Json_Get(Json *j, char *key);
/*
Will append a new key-value pair to the JSON object
*/
void Json_Append(Json *j, JsonKeyValuePair pair);
/*
Will convert a JSON object back to C raw string
similar to JavaScript's JSON.stringfy()
*/
char *Json_Stringfy(Json obj, unsigned int depth);
/*
Will print the JSON object to the stdout
*/
void Json_Print(Json *j, int depth);
- Note: more details about each API function may be found in doc strings
Jack has support for parsing JSON:
- Number
- String
- Arrays
- Nested & complex JSON objects
- Number starting with
-
or+
- Boolean values
- Null value
- Download the
include/jack.h
header file
wget https://raw.githubusercontent.com/edilson258/jack/master/include/jack.h
- Include in your program
#define JACK_IMPLEMENTATION
#include "jack.h"
int main() {
// your trash code goes here
}
- Note: The examples above expects the
jack.h
header file to be in the same directory as your program.
Feel free to play with it or maybe send me some PRs!