jsmn – faster, lighter JSON parser in C

jsmn (pronounced like ‘jasmine’) is a minimalistic JSON parser in C. It can be easily integrated into resource-limited or embedded projects.

You may read our another post “What is JSON and Understanding JSON syntax with simple example” to basics of JSON.

This post gives the details about how we can use jsmn to parse the JSON and create a structure from it.

$ git clone https://github.com/zserge/jsmn.git 
$ cd jsmn 

This directory also contains an example which shows how to do the initialisation required to parse the JSON and also parses following JSON,

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )


{"user": "johndoe", "admin": false, "uid": 1000, "groups": ["users", "wheel", "audio", "video"]}
$ make simple_example 

Execute this simple_example as,

$ ./simple_example 
- User: johndoe
- Admin: false
- UID: 1000
- Groups:
  * users
  * wheel
  * audio
  * video

As we can see in this example, all the initalisation API’s etc are written in jsmn.h header file, hence when we want to write our own parser code, we just need to include this header in our code and call the initialisation code.. As shown in below example of initialisation code,

#include "jsmn.h"

jsmn_parser p;
jsmntok_t t[128]; /* We expect no more than 128 JSON tokens */

r = jsmn_parse(&p, s, strlen(s), t, 128);

Reference – https://github.com/zserge/jsmn


1 thought on “jsmn – faster, lighter JSON parser in C”

Leave a Comment

Android Android Build system Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded