Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. Very low footprint JSON parser written in portable ANSI C.
  2.  
  3. * BSD licensed with no dependencies (i.e. just drop the C file into your project)
  4. * Never recurses or allocates more memory than it needs
  5. * Very simple API with operator sugar for C++
  6.  
  7. [![Build Status](https://secure.travis-ci.org/udp/json-parser.png)](http://travis-ci.org/udp/json-parser)
  8.  
  9. _Want to serialize?  Check out [json-builder](https://github.com/udp/json-builder)!_
  10.  
  11. Installing
  12. ----------
  13.  
  14. There is now a makefile which will produce a libjsonparser static and dynamic library.  However, this
  15. is _not_ required to build json-parser, and the source files (`json.c` and `json.h`) should be happy
  16. in any build system you already have in place.
  17.  
  18.  
  19. API
  20. ---
  21.  
  22.     json_value * json_parse (const json_char * json,
  23.                              size_t length);
  24.  
  25.     json_value * json_parse_ex (json_settings * settings,
  26.                                 const json_char * json,
  27.                                 size_t length,
  28.                                 char * error);
  29.  
  30.     void json_value_free (json_value *);
  31.  
  32. The `type` field of `json_value` is one of:
  33.  
  34. * `json_object` (see `u.object.length`, `u.object.values[x].name`, `u.object.values[x].value`)
  35. * `json_array` (see `u.array.length`, `u.array.values`)
  36. * `json_integer` (see `u.integer`)
  37. * `json_double` (see `u.dbl`)
  38. * `json_string` (see `u.string.ptr`, `u.string.length`)
  39. * `json_boolean` (see `u.boolean`)
  40. * `json_null`
  41.  
  42.  
  43. Compile-Time Options
  44. --------------------
  45.  
  46.     -DJSON_TRACK_SOURCE
  47.  
  48. Stores the source location (line and column number) inside each `json_value`.
  49.  
  50. This is useful for application-level error reporting.
  51.  
  52.  
  53. Runtime Options
  54. ---------------
  55.  
  56.     settings |= json_enable_comments;
  57.  
  58. Enables C-style `// line` and `/* block */` comments.
  59.  
  60.     size_t value_extra
  61.  
  62. The amount of space (if any) to allocate at the end of each `json_value`, in
  63. order to give the application space to add metadata.
  64.  
  65.     void * (* mem_alloc) (size_t, int zero, void * user_data);
  66.     void (* mem_free) (void *, void * user_data);
  67.  
  68. Custom allocator routines.  If NULL, the default `malloc` and `free` will be used.
  69.  
  70. The `user_data` pointer will be forwarded from `json_settings` to allow application
  71. context to be passed.
  72.  
  73.  
  74. Changes in version 1.1.0
  75. ------------------------
  76.  
  77. * UTF-8 byte order marks are now skipped if present
  78.  
  79. * Allows cross-compilation by honoring --host if given (@wkz)
  80.  
  81. * Maximum size for error buffer is now exposed in header (@LB--)
  82.  
  83. * GCC warning for `static` after `const` fixed (@batrick)
  84.  
  85. * Optional support for C-style line and block comments added (@Jin-W-FS)
  86.  
  87. * `name_length` field added to object values
  88.  
  89. * It is now possible to retrieve the source line/column number of a parsed `json_value` when `JSON_TRACK_SOURCE` is enabled
  90.  
  91. * The application may now extend `json_value` using the `value_extra` setting
  92.  
  93. * Un-ambiguate pow call in the case of C++ overloaded pow (@fcartegnie)
  94.  
  95. * Fix null pointer de-reference when a non-existing array is closed and no root value is present
  96.  
  97.  
  98.