All Projects → septag → cj5

septag / cj5

Licence: MIT license
Very minimal single header JSON5 parser in C99, derived from jsmn

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to cj5

nosj
a json parser written in pure bash
Stars: ✭ 33 (+0%)
Mutual labels:  json-parser
akka-cluster-minimal
Akka Cluster - absolute minimal
Stars: ✭ 16 (-51.52%)
Mutual labels:  minimal
dsm
Declarative Stream Mapping (DSM) is a stream de/serializer library for XML and JSON. DSM allows you to make custom parsing, filtering, transforming, aggregating, grouping on any JSON or XML document at stream time(read only once).
Stars: ✭ 23 (-30.3%)
Mutual labels:  json-parser
purity
Oh-My-ZSH prompt inspired by robbyrussell theme + pure prompt
Stars: ✭ 14 (-57.58%)
Mutual labels:  minimal
JsonFormatter
Easy, Fast and Lightweight Json Formatter. (Serializer and Deserializer)
Stars: ✭ 26 (-21.21%)
Mutual labels:  json-parser
dradis-docker
A Docker image with Dradis: A collaboration and reporting platform for IT security experts.
Stars: ✭ 13 (-60.61%)
Mutual labels:  minimal
json2dart-converter
Android Studio plugin for converting json to dart classes.
Stars: ✭ 35 (+6.06%)
Mutual labels:  json-parser
Ephesus
Ephesus is a minimalist Jekyll theme, designed for personal blog use.
Stars: ✭ 40 (+21.21%)
Mutual labels:  minimal
tinypool
🧵 A minimal and tiny Node.js Worker Thread Pool implementation (38KB)
Stars: ✭ 452 (+1269.7%)
Mutual labels:  minimal
minimum-viable-startpage
A very simple startpage to replace new tab in a browser of choice.
Stars: ✭ 61 (+84.85%)
Mutual labels:  minimal
wc18-cli
An easy command line interface for the 2018 World Cup
Stars: ✭ 15 (-54.55%)
Mutual labels:  json-parser
air
A hyper-minimal WordPress starter theme for developers built with Tailwind CSS.
Stars: ✭ 45 (+36.36%)
Mutual labels:  minimal
goide
Docker run to a sane vim-go setup
Stars: ✭ 19 (-42.42%)
Mutual labels:  minimal
DevFolio
A Modern Portfolio Template for Developers with easy setup process documented(with hosting).
Stars: ✭ 96 (+190.91%)
Mutual labels:  minimal
siimple
The minimal and themeable CSS toolkit for flat and clean designs
Stars: ✭ 525 (+1490.91%)
Mutual labels:  minimal
hugo-theme-texify
A minimal, latex-style hugo theme for personal blogging
Stars: ✭ 91 (+175.76%)
Mutual labels:  minimal
kolorist
A tiny utility to colorize stdin/stdout
Stars: ✭ 160 (+384.85%)
Mutual labels:  minimal
simple json
Simple way to dynamically convert from and to JSON using build-time generators given a type.
Stars: ✭ 15 (-54.55%)
Mutual labels:  json-parser
torsimany
💡✏️️ ⬇️️ JSON to Markdown converter - Generate Markdown from format independent JSON
Stars: ✭ 49 (+48.48%)
Mutual labels:  json-parser
JSONPath.sh
JSONPath implementation in Bash for filtering, merging and modifying JSON
Stars: ✭ 45 (+36.36%)
Mutual labels:  json-parser

cj5

Very minimal single header JSON5 parser in C99, derived from jsmn

What is json 5

It is just a less strict standard JSON, which is easier to read and write as well ass some nice added features, for more info see JSON5. Some Json5 features maybe incomplete or not working properly, but currently the features are tested:

  • Object keys may be an ECMAScript 5.1 IdentifierName.
  • Objects may have a single trailing comma.
  • Strings may be single quoted.
  • Strings may span multiple lines by escaping new line characters.
  • Strings may include character escapes.
  • Numbers may be hexadecimal.
  • Numbers may have a leading or trailing decimal point.
  • Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.
  • Numbers may begin with an explicit plus sign.
  • Single and multi-line comments are allowed.
  • Additional white space characters are allowed.
  • Multiline comments are allowed

Features

  • No memory allocations. All allocatrions are managed on the user side
  • Fast and Minimal.
  • standard C library functions (memory,string functions) can be overriden
  • Easy to use API (one function to parse)
  • Portable C API
  • Helper functions to use parsed data in DOM manner

Usage

The main function to parse json is cj5_parse. like jsmn, you provide all tokens to be filled as an array and provide the maximum count The result will be return in cj5_result struct, and num_tokens will represent the actual token count that is parsed.
In case of errors, cj_result.error will be set to an error code. Here's a quick example of the usage, first define CJ5_IMPLEMENT to include the implementation:

        #define CJ5_IMPLEMENT
        #include "cj5.h"

        cj5_token tokens[32];
        cj5_result r = cj5_parse(g_json, (int)strlen(g_json), tokens, 32);
        
        if (r.error != CJ5_ERROR_NONE) {
            if (r.error == CJ5_ERROR_OVERFLOW) {
                // you can use r.num_tokens to determine the actual token count and reparse
                printf("Error: line: %d, col: %d\n", r.error_line, r.error_code);    
            }
        } else {
            // use token helper functions (see below) to access the values 
            float my_num = cj5_seekget_float(&r, 0, "my_num", 0 /* default value if not found*/ );
        } 

NOTE: Unlike jsmn, if number of parsed tokens exceeds the provided ones, parser doesn't return immediately with an error. But parses the JSON to the end, counts all needed tokens and returns with an CJ5_ERROR_OVERFLOW, so the user can choose to reparse the json with new memory requirements.

Links

  • jsmn: Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
  • sjson: Fast and portable C single header json Encoder/Decoder

License (MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].