All Projects → rafagafe → Tiny Json

rafagafe / Tiny Json

Licence: mit
The tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Tiny Json

Serial Studio
Multi-purpose serial data visualization & processing program
Stars: ✭ 1,168 (+819.69%)
Mutual labels:  microcontroller, embedded
Lv drivers
TFT and touch pad drivers for LVGL embedded GUI library
Stars: ✭ 84 (-33.86%)
Mutual labels:  microcontroller, embedded
Ejdb
🏂 EJDB 2.0 — Embeddable JSON Database engine C library. Simple XPath like query language (JQL). Websockets / Android / iOS / React Native / Flutter / Java / Dart / Node.js bindings. Docker image.
Stars: ✭ 1,187 (+834.65%)
Mutual labels:  json, embedded
Cssparser.js
cssparser.js is a parser that generate json from css with matched orders & structures.
Stars: ✭ 61 (-51.97%)
Mutual labels:  json, parser
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (-25.98%)
Mutual labels:  json, parser
Incubator Nuttx Apps
Apache NuttX Apps is a collection of tools, shells, network utilities, libraries, interpreters and can be used with the NuttX RTOS
Stars: ✭ 65 (-48.82%)
Mutual labels:  microcontroller, embedded
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-35.43%)
Mutual labels:  json, parser
Parson
Lightweight JSON library written in C.
Stars: ✭ 965 (+659.84%)
Mutual labels:  json, parser
Java
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
Stars: ✭ 1,308 (+929.92%)
Mutual labels:  json, parser
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+7969.29%)
Mutual labels:  json, parser
Barely json
A Python parser for data that only looks like JSON
Stars: ✭ 56 (-55.91%)
Mutual labels:  json, parser
Unqlite
An Embedded NoSQL, Transactional Database Engine
Stars: ✭ 1,583 (+1146.46%)
Mutual labels:  json, embedded
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+703.94%)
Mutual labels:  json, parser
Daplink
Stars: ✭ 1,162 (+814.96%)
Mutual labels:  microcontroller, embedded
Utensor cgen
C++ code generator for uTensor https://utensor-cgen.readthedocs.io/en/latest/
Stars: ✭ 42 (-66.93%)
Mutual labels:  microcontroller, embedded
Sming
Sming - Open Source framework for high efficiency native ESP8266 development
Stars: ✭ 1,197 (+842.52%)
Mutual labels:  microcontroller, embedded
Librini
Rini is a tiny, non-libc dependant, .ini file parser programmed from scratch in C99.
Stars: ✭ 25 (-80.31%)
Mutual labels:  parser, embedded
Xml Js
Converter utility between XML text and Javascript object / JSON text.
Stars: ✭ 874 (+588.19%)
Mutual labels:  json, parser
Utensor
TinyML AI inference library
Stars: ✭ 1,295 (+919.69%)
Mutual labels:  microcontroller, embedded
Forge
Functional style JSON parsing in Kotlin
Stars: ✭ 106 (-16.54%)
Mutual labels:  json, parser

tiny-json

Build Status GitHub contributors

tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable.

It is not only a tokenizer. You can get data in string format or get the primitives values in C type variables without performance loss.

You can get the JSON fields one on one. Or get their values by their names. This helps you to save a lot of source code lines and development time.

  • It does not use recursivity.
  • It does not use dynamic memory. The memory you use can be reserved statically.
  • It has not limits in nested level in arrays or json objects.
  • The JSON property number limit is determined by the size of a buffer that can be statically reserved.

If you need create JSON strings please visit: https://github.com/rafagafe/json-maker

Philosophy

When parsing a JSON text string a tree is created by linking json_t structures. Navigating or querying this tree is very easy using the API functions.

To maintain reduced memory usage and fast processing the strings are not copied. When you request the value of a JSON element, a reference is returned within the original string with the JSON.

To facilitate the processing of the data the returned strings are null-terminated strings. This is achieved by setting the null character to JSON control characters such as commas, brackets, braces, and quotation marks.

API

Two types are defined in tiny-json API. One is jsonType_t. It is an enumeration with the types of JSON fields. And the other is json_t. It is a structure that you don't need know its content.

typedef enum {
    JSON_OBJ, JSON_ARRAY, JSON_TEXT, JSON_BOOLEAN,
    JSON_INTEGER, JSON_REAL, JSON_NULL
} jsonType_t;

To parse a JSON string we use the function json_create(). We pass it an array of json_t for it can allocate JSON fields. If the JSON string is bad format or has more fields than the array it returns a null pointer.

enum { MAX_FIELDS = 4 };
json_t pool[ MAX_FIELDS ];

char str[] = "{ \"name\": \"peter\", \"age\": 32 }";	

json_t const* parent = json_create( str, pool, MAX_FIELDS );
if ( parent == NULL ) return EXIT_FAILURE;

To get a field by its name we use the function json_getProperty. If the field does not exist it returns a null pointer. And to get the type of a field we use the function json_getType ().

json_t const* namefield = json_getProperty( parent, "name" );
if ( namefield == NULL ) return EXIT_FAILURE;
if ( json_getType( namefield ) != JSON_TEXT ) return EXIT_FAILURE;

To get the value of a filed in string format we use the function json_getValue(). It always returns a valid null-teminated string.

char const* namevalue = json_getValue( namefield );
printf( "%s%s%s", "Name: '", namevalue, "'.\n" );

In primitive type fileds we can use a especific funtion to get its value in a C type like json_getInteger() or still use json_getValue() to get its value in text format.

json_t const* agefield = json_getProperty( parent, "age" );
if ( agefield == NULL ) return EXIT_FAILURE;
if ( json_getType( agefield ) != JSON_INTEGER ) return EXIT_FAILURE;

int64_t agevalue = json_getInteger( agefield );
printf( "%s%lld%s", "Age: '", agevalue, "'.\n" );

char const* agetxt = json_getValue( agefield );
printf( "%s%s%s", "Age: '", agetxt, "'.\n" );

To see nested JSON objects and arrays please read example-01.c.

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].