Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Very low footprint DOM-style JSON parser written in portable ANSI C

License

NotificationsYou must be signed in to change notification settings

json-parser/json-parser

Repository files navigation

Very low footprint DOM-style JSON parser written in portable C89 (sometimes referred to as ANSI C).

  • BSD licensed with no dependencies (i.e. just dropjson.c andjson.h into your project)
  • Never recurses or allocates more memory than it needs to represent the parsed JSON
  • Very simple API with operator sugar for C++

Build Status

Want to serialize? Check outjson-builder!

Installing

There is now a makefile which will produce a libjsonparser static and dynamic library. However, thisisnot required to build json-parser, and the source files (json.c andjson.h) should be happyin any build system you already have in place.

API

json_value*json_parse (constjson_char*json,size_tlength);json_value*json_parse_ex (json_settings*settings,constjson_char*json,size_tlength,char*error);voidjson_value_free (json_value*);

Thetype field ofjson_value is one of:

  • json_object (seeu.object.length,u.object.values[x].name,u.object.values[x].value)
  • json_array (seeu.array.length,u.array.values)
  • json_integer (seeu.integer)
  • json_double (seeu.dbl)
  • json_string (seeu.string.ptr,u.string.length)
  • json_boolean (seeu.boolean)
  • json_null

Compile-Time Options

Unless otherwise specified, compile definitions must be provided both when compilingjson.c and when compiling any of your own source files that includejson.h.

JSON_TRACK_SOURCE

Stores the source location (line and column number) inside eachjson_value.

This is useful for application-level error reporting.

json_int_t

By default,json_int_t is defined aslong under C89 andint_fast64_t otherwise. For MSVC it is defined as__int64 regardless of language standard support.

Optionally, you may definejson_int_t to be your own preferred type name for integer types parsed from JSON documents. It must be a signed integer type, there is no support for unsigned types. If you specify a raw primitive type withoutsigned orunsigned (and not a typdef),JSON_INT_MAX will be calculated for you. Otherwise, you must provide your own definition ofJSON_INT_MAX as the highest positive integer value that can be represented byjson_int_t.

Example usage:

  • -Djson_int_t=short
  • "-Djson_int_t=signed char" -DJSON_INT_MAX=127
  • "-Djson_int_t=long long"
  • -Djson_int_t=__int128

Runtime Options

settings |=json_enable_comments;

Enables C-style// line and/* block */ comments.

size_tvalue_extra

The amount of space (if any) to allocate at the end of eachjson_value, inorder to give the application space to add metadata.

void* (*mem_alloc) (size_t,intzero,void*user_data);void (*mem_free) (void*,void*user_data);

Custom allocator routines. If NULL, the defaultmalloc andfree will be used.

Theuser_data pointer will be forwarded fromjson_settings to allow applicationcontext to be passed.

Changes in version 1.1.0

  • UTF-8 byte order marks are now skipped if present

  • Allows cross-compilation by honoring --host if given (@wkz)

  • Maximum size for error buffer is now exposed in header (@LB--)

  • GCC warning forstatic afterconst fixed (@batrick)

  • Optional support for C-style line and block comments added (@Jin-W-FS)

  • name_length field added to object values

  • It is now possible to retrieve the source line/column number of a parsedjson_value whenJSON_TRACK_SOURCE is enabled

  • The application may now extendjson_value using thevalue_extra setting

  • Un-ambiguate pow call in the case of C++ overloaded pow (@fcartegnie)

  • Fix null pointer de-reference when a non-existing array is closed and no root value is present

About

Very low footprint DOM-style JSON parser written in portable ANSI C

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp