Commit Graph

68 Commits

Author SHA1 Message Date
Petri Lehtinen
17b5fdd94b Add JSON_REAL_PRECISION
Fixes #178.
2014-04-30 12:46:34 +03:00
Petri Lehtinen
30fdf6067e Update copyrights for 2014 2014-01-28 09:16:05 +02:00
Chip Salzenberg
dcaa90d21e dump \u sequences as upper case for readability (just like error messages) 2013-09-27 17:32:25 -07:00
Chip Salzenberg
9c259c07aa Support \u0000 - add size_t string lengths to API, load and dump \u000, etc.
Also:
  Steal strings during parsing for half the mallocs!
  Change all input-caused assertions to errors.  No crashes please, we're programmers.
2013-09-27 17:32:06 -07:00
Petri Lehtinen
2489ea90b1 Update copyrights for 2013 2013-07-23 13:20:06 +03:00
Petri Lehtinen
61cba2ae50 Merge branch '2.4' 2013-04-15 08:49:47 +03:00
Petri Lehtinen
867079c820 json_dump*(): Don't crash if json is NULL and JSON_ENCODE_ANY is set 2013-04-15 08:49:09 +03:00
Petri Lehtinen
6281d1c549 Merge pull request #108 from Zillode/1edff47af38a2335f88300ee6dc437118f5a20ff
Fixes redefined warnings ("_GNU_SOURCE")
2013-04-02 05:40:49 -07:00
Lode Hoste
1edff47af3 Do not define _GNU_SOURCE is already defined 2013-03-14 21:34:11 +01:00
Jacob Potter
f86bb0377f Mark some constant data as const.
Issue #95.
2012-12-10 08:47:00 +02:00
Petri Lehtinen
37bc3bbf4b Tweak slash escaping 2012-06-29 13:25:02 +03:00
Petri Lehtinen
2d46ea069b Merge branch 'fix-slash' of git://github.com/jrbasso/jansson
Fixes #81.
2012-06-29 13:24:55 +03:00
Juan Basso
b217cd6689 Created flag to dump escaping slash 2012-06-28 22:04:36 -04:00
Juan Basso
a0c262d08b Escaping the slash when dump 2012-06-27 23:54:08 -04:00
Petri Lehtinen
ff0c05b8f1 Support building on Windows
Jansson now builds correctly with Visual C++ Express 2010.
2012-04-29 22:09:29 +03:00
Petri Lehtinen
3c6e36ba2d Update copyright notices for 2012 2012-03-20 20:55:55 +02:00
Petri Lehtinen
a2381948bb Make hashtable less generic
This will make it possible to implement json_object_foreach(). It
should also have some (positive) effect on speed.
2012-01-24 21:01:23 +02:00
Petri Lehtinen
c4a7bf90cf Revert "json_dump_file: Open the output file in wb mode"
JSON is read as text, so line endings should be preserved.

This reverts commit 32cd821273.
2011-11-14 21:16:36 +02:00
Petri Lehtinen
0f2cdd70ff Avoid problems with object's serial number growing too big
Transform serial key comparison from substraction to real comparison.
Reset serial to zero in json_object_clear() to avoid it growing out of
bounds when reusing objects.

Closes GH-40.
Closes GH-41.
2011-11-14 21:01:13 +02:00
Petri Lehtinen
32cd821273 json_dump_file: Open the output file in wb mode
For maximum compatibility.
2011-10-07 20:52:54 +03:00
Petri Lehtinen
d7ddbf3661 Make real number encoding and decoding work under all locales
The decimal point '.' is changed to locale's decimal point
before/after JSON conversion to make C standard library's
locale-specific string conversion functions work correctly.

All the tests now call setlocale(LC_ALL, "") on startup to use the
locale set in the environment.

Fixes GH-32.
2011-10-02 21:31:17 +03:00
Petri Lehtinen
b6d0191e51 Implement all other encoding functions using json_dump_callback
This way we can check for JSON_ENCODE_ANY flag in one place only.
2011-09-24 21:10:34 +03:00
JKL
c7d543d36c new typedef json_dump_callback_t, function json_dump_callback 2011-06-30 21:47:12 +03:00
Petri Lehtinen
636d5f60f9 Add JSON_ENCODE_ANY flag to allow encoding any JSON value
Closes GH-19.
2011-05-14 12:57:12 +03:00
Petri Lehtinen
4be9e9e7fe Add custom memory allocation
Thanks to Basile Starynkevitch for the suggestion and initial patch.
Thanks to Jonathan Landis and Deron Meranda for showing how this can
be utilized for implementing secure memory operations.
2011-02-17 10:10:53 +02:00
Petri Lehtinen
fa7c2ea070 Update copyright notices for 2011 2011-01-22 13:43:14 +02:00
Petri Lehtinen
f8d0e01e46 Change the maximum indentation size to 32 spaces in encoder
This is to free up bits from the flags parameter of json_dump
functions. I'm pretty sure no-one needs 256 spaces of indentation when
pretty-printing JSON values...

This is a backwards incompatible change.
2010-08-13 22:12:36 +03:00
Petri Lehtinen
ffbab6fedd Change the underlying type of JSON integer from long to json_int_t
json_int_t is typedef'd to long long if it's supported, or long
otherwise. There's also some supporting things, like the
JSON_INTEGER_FORMAT macro that expands to the printf() conversion
specifier that corresponds to json_int_t's actual type.

This is a backwards incompatible change.
2010-08-13 22:07:20 +03:00
Petri Lehtinen
014c49c285 Change JSON integer's underlying type from int to long
This is a backwards incompatible change.
2010-08-10 21:45:18 +03:00
Petri Lehtinen
68f2861e92 Unify unsigned integer usage in the API
Replace all occurences of unsigned int and unsigned long with size_t.

This is a backwards incompatible change, as the signature of many API
functions changes.
2010-06-15 15:38:59 +03:00
Petri Lehtinen
dec3ad498e Merge branch '1.2' 2010-05-20 18:47:30 +03:00
Petri Lehtinen
453e4c0aa2 Zero the visited flag after an encoding error
When encoding an array or object ends in an error, the visited flag
wasn't zeroed, causing subsequent encoding attempts to fail. This
patch fixes the problem by always zeroing the visited flag.
2010-05-14 09:23:35 +03:00
Petri Lehtinen
2630980f49 Zero the visited flag after encoding an empty array or object
Encoding an empty array or object worked, but encoding it again
(possibly after adding some items) failed, because the visited flag
(used for detecting circular references) wasn't zeroed.
2010-05-14 09:05:56 +03:00
Petri Lehtinen
49880cbabe Merge branch '1.2' 2010-03-23 08:15:19 +02:00
Petri Lehtinen
f18ef5144a Implement JSON_PRESERVE_ORDER encoding flag
With this encoding flag, the object key-value pairs in output are in
the same order in which they were first inserted into the object.

To make this possible, a key of an object is now a serial number plus
a string. An object keeps an increasing counter which is used to
assign serial number to the keys. Hashing, comparison and public API
functions were changed to act only on the string part, i.e. the serial
number is ignored everywhere else but in the encoder, where it's used
to order object keys if JSON_PRESERVE_ORDER flag is used.
2010-02-11 20:48:56 +02:00
Petri Lehtinen
286823227c Make int32_t available on all systems
Use AC_TYPE_INT32_T and include inttypes.h (if it exists) instead of
stdint.h for maximum portability.
2010-02-06 21:11:41 +02:00
Petri Lehtinen
08dc8d9baf Add year 2010 to copyright notices 2010-02-02 21:26:11 +02:00
Petri Lehtinen
e7a5dc58e6 Merge branch '1.1'
Conflicts:
	configure.ac
	doc/conf.py
2009-12-21 12:52:25 +02:00
Petri Lehtinen
ec96cbf016 Encode reals correctly
This patch changes the sprintf format from "%0.17f" to "%.17g", as the
f format specifier doesn't print the exponent at all. This caused
losing precision in all but the most simple cases.

Because the g specifier doesn't print the decimal fraction or exponent
if they're not needed, a ".0" has to be appended by hand in these
cases. Otherwise the value's type changes from real to integer when
decoding again.

Thanks to Philip Grandinetti for reporting this issue.
2009-12-18 00:05:06 +02:00
Petri Lehtinen
19a606d736 Implement JSON_SORT_KEYS encoding flag
With this flag, the objects are sorted by key when encoding.
2009-12-16 23:12:39 +02:00
Petri Lehtinen
50031440a3 Implement JSON_ENSURE_ASCII encoding flag
With this flag, all Unicode characters outside the ASCII range are
escaped.
2009-12-05 22:55:30 +02:00
Petri Lehtinen
d67aeb9739 Use int32_t instead of plain int with Unicode code points
On some architectures, int just isn't big enough to hold all Unicode
code points.
2009-12-02 23:53:54 +02:00
Petri Lehtinen
f236c14dc5 dump: Revise whitespace usage
- Never append newline to output
- By default, add spaces between array and object items for more
  readable output
- Introduce the flag JSON_COMPACT to not add the aforementioned spaces
2009-11-04 22:09:40 +02:00
Petri Lehtinen
86dc1d629b Fix indentation
No functional changes.
2009-10-16 21:20:38 +03:00
Petri Lehtinen
4cd777712b Enhance handling of circular references
It's now an error to try to add an object or array to itself. The
encoder checks for circular references and fails with an error status
if one is detected.
2009-10-15 21:02:27 +03:00
Petri Lehtinen
79009e62c1 json_dumps: Close the strbuffer if dumping fails 2009-10-15 20:54:32 +03:00
Petri Lehtinen
185e107d24 Don't use non-portable asprintf()
Thanks to Adam Strzelecki for reporting.
2009-10-13 15:40:26 +03:00
Petri Lehtinen
ca7703fbd1 Merge branch '1.0'
Conflicts:
	configure.ac
	doc/conf.py
2009-10-11 21:51:54 +03:00
Petri Lehtinen
9c5a8430db Make it compile on platforms where char is unsigned
Linux on powerpc seems to be one such platform.
2009-10-01 21:54:45 +03:00
Petri Lehtinen
743af38e7f Use unsigned long instead of uint32_t
Some day we will have ANSI C compatibility... This change doesn't make
the API backwards incompatible because uint32_t was only used in flags
to json_dump*() and the flags are meant to be used only by ORing
constants and macro output, and actually currently only JSON_INDENT
can be used.
2009-09-13 13:16:34 +03:00