• Stars
    star
    268
  • Rank 153,144 (Top 4 %)
  • Language
    C
  • Created almost 15 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a JSON parser and printer library in C. easy to integrate with any model.

libjson - simple and efficient json parser and printer in C

Introduction

libjson is a simple library without any dependancies to parse and pretty print the JSON format (RFC 4627). The JSON format is a concise and structured data format.

Features

  • interruptible parser: append data to the state how you want it.
  • No object model integrated
  • Small codebase: handcoded parser and efficient factorisation make the code smalls and perfect for embedding.
  • Fast: use efficient code and small parsing tables for maximum efficiency.
  • Full JSON support.
  • UTF8 validation of the input.
  • No number conversion: user convert data the way they want.
  • Secure: optional limits on nesting level, and on data size.
  • Optional comments: in YAML/python style and C style.
  • Optional user defined allocation functions.

libjson parser is an interruptible handcoded state parse. the parser takes character or string as input. Since it's interruptible, it's up to the user to feed the stream to the parser, which permits complete flexibility as to whether the data is coming from a pipe, a network socket, a file on disk, a serial line, or crafted by the user.

The parser doesn't create an object tree for you, but each time it comes up with an element in this data, it just callback to the user with the type found and for some type, the data associated with it. It can be compared to the SAX way of XML, hence it's called SAJ (Simple API for JSon).

The parser doesn't convert number to any native C format, but instead callback with a string that is a valid JSon number. JSon number can be of any size, so that's up to user to decide whetever or not, the number can map to native C type int32_t, int64_t, or a complex integer type. As well the user has a choice to refuse the integer at the callback stage if the length is not appropriate.

The parser optionally allows YAML and/or C comments to be ignored if the config structure is set accordingly, otherwise a JSON_ERROR_COMMENT_NOT_ALLOWED is returned.

Embedding & Build system

The primary use case of this pieces of code is providing JSON capability to your program or library, without adding an extra build dependency. You can add it to your project directly, and integrate it without any fuss.

The "build system" available with the library is just a way to test that everything in the library conforms to specifications and features. It's not necessarily intended as a way to build portable dynamic library (.so or .dll). It should works in simple case of building on Linux and BSDs though.

For others use (eg. windows, OS X, obscure unixes), it is much simpler to integrate the library in your program or library directly.

Simple build fixes to build on more platforms will be accepted though.

Contributing

Open a pull request with your new feature, simple code fix, or documentation fixes. Please conform to coding style, and to the spirit of the library: policy is not imposed by the library.

The Parser API

The parser API is really simple, totaling only 5 API calls:

  • json_parser_init
  • json_parser_char
  • json_parser_string
  • json_parser_is_done
  • json_parser_free

json_parser_init initializes a new parser context from a parser config and takes a callback + userdata. This callback function is used everything the parser need to communicate a type and value to the client side of the library.

json_parser_char take one character and inject it in the parser. on parsing success it will return a 0 value, but on parsing error it returns a parsing error that represents the type of the error encounters. see JSON_ERROR_* for the full set of return values.

json_parser_string is similar to json_parser_char except that it takes a string and a length. it also returns the number of character processed, which is useful when an parser error happened in the stream to pinpoint where.

json_parser_is_done permits to test whetever or not the parser is in a terminated state. it involves not beeing into any structure.

json_parser_free is the opposite of init, it just free the allocated structure.

The Printer API

the printer API is simple too:

  • json_printer_init
  • json_printer_free
  • json_printer_pretty
  • json_printer_raw

json_printer_init initialise a printing context and takes a callback + userdata that will be called for every character that the printer wants to output. the caller can have the printer callback redirect to anything it wants.

json_printer_free is the opposite of init

json_printer_raw takes a json type and an optional data and length value depending on the type. it's up to the caller to verify that the order of type are JSON-compliant, otherwise the generated document won't be able to be parsed again.

json_printer_pretty works like json_printer_raw but is targetted for human reading by appending newlines and spaces

Jsonlint utility program

jsonlint utility provided with the library to verify, or reformat json stream. also useful as example on how to use the library.

More Repositories

1

hs-gauge

Lean Haskell Benchmarking
Haskell
90
star
2

hs-git

git protocol and storage in pure haskell
Haskell
66
star
3

language-java

Java parser and printer for haskell
Haskell
65
star
4

hs-connection

simple client connection library in haskell with builtin features: SSL/TLS, SOCKS, session management.
Haskell
61
star
5

hit

library to manipulate git repositories in haskell (no bindings)
Haskell
48
star
6

hs-memory

haskell memory
Haskell
48
star
7

hs-hourglass

efficient and simpler time API for haskell
Haskell
46
star
8

professor

haskell prof file CLI/Curses tool
Haskell
32
star
9

hs-cryptohash

efficient and practical cryptohashing in haskell. DEPRECATED in favor of cryptonite
Haskell
31
star
10

hs-cli

Command Line Interface Utility (Printing, Formatting, Options parsing) for Haskell
Haskell
24
star
11

hs-cipher-aes

DEPRECATED - use cryptonite - a comprehensive fast AES implementation for haskell that supports aesni and advanced cryptographic modes.
C
22
star
12

hs-crypto-cipher

DEPRECATED by cryptonite; A collection of cryptographic block and stream ciphers in haskell
Haskell
22
star
13

hs-asn1

ASN1 Raw/BER/DER/CER reader/writer in haskell
Haskell
22
star
14

hs-socks

Socks proxy library for haskell
Haskell
20
star
15

cabal-db

Various cabal query commands wrapped in a simple CLI tool
Haskell
18
star
16

hs-securemem

abstraction for auto scrubbing and const time Eq, memory chunk
Haskell
17
star
17

hs-libgit

haskell wrapper for git
Haskell
17
star
18

hs-packer

Fast serialization in haskell
Haskell
15
star
19

udbus

micro dbus library for embedding
C
13
star
20

ghc-core-html

Read ghc-core with style. javascript and CSS style.
Haskell
13
star
21

ocaml-inotify

ocaml inotify binding
OCaml
12
star
22

rust-pvss

PVSS & Scrape in rust
Rust
9
star
23

hs-siphash

siphash algorithm in haskell
Haskell
9
star
24

hs-crypto-pubkey

DEPRECATED - use cryptonite - Cryptographic public key related algorithms in haskell (RSA,DSA,DH,ElGamal)
Haskell
9
star
25

hs-crypto-platform

crypto platform for haskell
Haskell
8
star
26

hsco

haskell source code optimizer (do automatic renames, style change of haskell and cabal files)
Haskell
8
star
27

hs-unix-memory

Unix mmap (and co) bindings for haskell
Haskell
8
star
28

hs-cstruct

Haskell CStruct access with advanced type system
Haskell
7
star
29

hs-pem

PEM format writer/reader in haskell
Haskell
7
star
30

hs-fileformat

some file format detection without using libfile or file.
Haskell
7
star
31

hs-crypto-pubkey-types

Crypto Public Key algorithm generic types.
Haskell
7
star
32

hs-tls-extra

TLS extra definition and helpers.
Haskell
6
star
33

hs-byteable

abstraction for sequence of bytes
Haskell
6
star
34

haskell-ci

some haskell related CI
Haskell
5
star
35

hs-scraps

Scrap modules - random bits and bobs
Haskell
5
star
36

haskell-pkg-guidelines

guidelines for haskell packages
5
star
37

hs-crypto-numbers

DEPRECATED - use cryptonite - Cryptographic number related function and algorithms
Haskell
5
star
38

s-expr

lightweight and customizable rust s-expression (s-expr) parser and printer
Rust
5
star
39

hs-cprng-aes

Crypto Pseudo Random Number Generator using AES in counter mode
Haskell
5
star
40

hs-cpu

Cpu properties and information helpers for haskell
Haskell
5
star
41

zhi

Chinese tools/input for english speaker.
Haskell
4
star
42

hs-udbus

Small Haskell DBus implementation
Haskell
4
star
43

psec

experiment for packages security (and other major) issues. reporting and querying APIs
Haskell
4
star
44

hs-crypto-random

DEPRECATED - use cryptonite - Cryptographic random class and entropy gatherer with safe API for haskell
Haskell
4
star
45

gh-labeler

create/delete/sync github issue labels easily from the CLI
Haskell
4
star
46

hess

Haskell embedded Cascading Style Sheet
Haskell
3
star
47

hs-simple-readline

Simple readline like feature in haskell for modern terminals.
Haskell
3
star
48

hs-xenstore

Haskell xenstore client library
Haskell
3
star
49

go-circuit

secret sharing and high level circuit handling in golang
Go
3
star
50

gitcache

simple git clone cache use and management tool
Haskell
3
star
51

hs-tls-debug

debug tools for the haskell tls framework
Haskell
3
star
52

cabal-browser

local haskell package browser
Haskell
3
star
53

hs-net

haskell network related packages
Haskell
3
star
54

werbolg

multi language execution environment
Rust
3
star
55

ooofa

CLI 2fa
Rust
3
star
56

tasty-kat

KAT (Known Answer Tests) support for tasty
Haskell
3
star
57

string-benchmarks

string benchmarks
Haskell
3
star
58

bip39-dict

rust binary encoding using BIP39 wordlist
Rust
3
star
59

hs-bytedump

haskell configurable dump byte helpers
Haskell
3
star
60

socksmaster

a simple pseudo VPN of fortune using multiple socks tunnels behind some routing table.
Haskell
3
star
61

eccoxide

elliptic curve cryptography in rust
Rust
3
star
62

ocaml-dbus

ocaml dbus bindings
C
3
star
63

hs-adbwrapper

simple Haskell wrapper for Android's adb utility
Haskell
3
star
64

happlet-power

tiny gtk systray battery/power reporting app
Haskell
2
star
65

hs-linux-service

set of random service bindings for linux
Haskell
2
star
66

hs-crypto-cipher-types

usual types for cryptographic ciphers (block&stream)
Haskell
2
star
67

aotp

another OTP rust library
Rust
2
star
68

vault

Utility to store secrets, securely on disk.
Haskell
2
star
69

cbored

CBOR exact reader and writer
Rust
2
star
70

setup

setup stuff
Shell
2
star
71

tvm

Tiny VM Manager
Haskell
2
star
72

hs-cipher-rc4

rc4 stream cipher for haskell
Haskell
2
star
73

webkit

mirror of darcs webkit
Haskell
2
star
74

haterm

haskell GTK3 Vte-based terminal
Haskell
2
star
75

language-c

mirror of darcs' language-c
Haskell
2
star
76

hs-cryptohash-conduit

Simple conduit function for cryptohash
Haskell
2
star
77

hstoolbox

Random Haskell Tools
Haskell
2
star
78

hs-simpletemplate

very simple and efficient string template module in haskell with binary caching
Haskell
2
star
79

hs-crypto-random-api

An haskell abstraction for simpler random byte generator.
Haskell
2
star
80

hs-gir

Haskell's GIR parsing library
Haskell
2
star
81

hs-crypto-types

Basic cryptographic types with some better security properties
Haskell
2
star
82

wikiengine

Wiki syntax and renderer in haskell
Haskell
2
star
83

hs-gen-storable

Generate haskell code to interfaces with memory from C like definitions
Haskell
2
star
84

hs-afis

Anti-forensic information splitter algorithm in haskell (same as LUKS AFsplit algorithm)
Haskell
2
star
85

hs-nar-util

NAR utilities in haskell
Haskell
1
star
86

hs-risk

risky experiments
Haskell
1
star
87

cabal-signature

an experiment with signing/verifying cabal packages and an ad-hoc WoT infrastructure.
Haskell
1
star
88

gitcontrol

git tests
Haskell
1
star
89

rust-gitcontrol

rewrite of gitcontrol to rust
Rust
1
star
90

aotp-tools

another OTP set of tools
Rust
1
star
91

hs-auth-avl

Haskell authenticated AVL
Haskell
1
star
92

hs-asn1dump

ASN.1 debug tool
Haskell
1
star
93

smoke

smoke test framework -- generator, unit, property tests
Rust
1
star
94

hs-xyz-test

xyz
Haskell
1
star
95

hs-bsparse

bytestring parser
Haskell
1
star
96

sysui

misc system ui in haskell
Haskell
1
star
97

quarry

experiments with storage
Haskell
1
star
98

api-diff

api diff
Haskell
1
star
99

ocaml-udev

ocaml udev bindings
C
1
star
100

xfiles

my own file utilities
Haskell
1
star