Skip to content

A header-only library for parsing JSON data in C

Notifications You must be signed in to change notification settings

edilson258/jack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jack

Jack is header-only library for parsing JSON data in C.

Examples

#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!"
}

Brief API explanation

/*
    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

Features

Jack has support for parsing JSON:

  • Number
  • String
  • Arrays
  • Nested & complex JSON objects
  • Number starting with - or
  • Boolean values
  • Null value

Try it now

  1. Download the include/jack.h header file
wget https://raw.githubusercontent.com/edilson258/jack/master/include/jack.h
  1. 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.

Contribuitions

Feel free to play with it or maybe send me some PRs!

About

A header-only library for parsing JSON data in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages