summaryrefslogtreecommitdiff
path: root/src/json.c
Commit message (Collapse)AuthorAgeFilesLines
* Minor doc string fixes in json.cEli Zaretskii2018-06-161-2/+3
| | | | * src/json.c (Fjson_serialize, Fjson_insert): Fix 'usage'.
* Also allow custom false and null when serializing to JSONJoão Távora2018-06-151-82/+113
| | | | | | | | | | | | | | | | | * doc/lispref/text.texi (Parsing JSON): Describe new arguments of json-serialize and json-insert. * src/json.c (enum json_object_type, struct json_configuration): Move up in file before first usage. (lisp_to_json_toplevel, lisp_to_json_toplevel_1, lisp_to_json): Accept a struct json_configuration*. (Fjson_serialize, Fjson_insert): Accept multiple args. (json_parse_args): Accept new boolean configure_object_type. * test/src/json-tests.el (json-serialize, json-insert): Update forward decls. (json-parse-with-custom-null-and-false-objects): Add assertions for json-serialize.
* Support custom null and false objects when parsing JSONJoão Távora2018-06-151-54/+82
| | | | | | | | | | | | | | | | | | * doc/lispref/text.texi (Parsing JSON): Describe new :null-object and :false-object kwargs to json-parse-string and json-parse-buffer. * src/json.c (struct json_configuration): New type. (json_to_lisp): Accept a struct json_configuration* param. (json_parse_args): Rename from json_parse_object_type. (Fjson_parse_string): Rework docstring. (Fjson_parse_string, Fjson_parse_buffer): Update call to json_to_lisp. (syms_of_json): Two new syms, QCnull_object and QCfalse_object. * test/src/json-tests.el (json-parse-with-custom-null-and-false-objects): New test.
* Fix pointer misuse in JSON parserPaul Eggert2018-06-091-32/+28
| | | | | | | | | * src/json.c (lisp_to_json_toplevel_1): Fix pointer misuse not caught by C type checking (json_t ** converted to void * where the program expected json_t *). Bug caught on Fedora 28 x86-64 via './configure CFLAGS="-g3 -O2 -fsanitize=address" CANNOT_DUMP=yes'. Avoid similar problems in the future by rewriting to use json_t * instead of json_t **.
* Accept plists when serializing and parsing JSONJoão Távora2018-06-071-24/+73
| | | | | | | | | | | | | | | | * doc/lispref/text.texi (Parsing JSON): Mention plist support. * src/json.c (lisp_to_json_toplevel_1): Serialize plists to json. (Fjson_serialize): Mention plists in docstring. (enum json_object_type): Add json_object_plist. (json_to_lisp): Parse JSON into plists. (json_parse_object_type): Consider plists. (Fjson_parse_string): Mention plists in docstring. (syms_of_json): New Qplist sym_of_json. (lisp_to_json): Update comment. * test/src/json-tests.el (json-serialize/object) (json-parse-string/object): New plist tests.
* ; Fix arglist doc of json parse functionsBasil L. Contovounesios2018-02-031-2/+2
| | | | | * src/json.c (Fjson_parse_string, Fjson_parse_buffer): Fix "usage:" arglist doc.
* Update copyright year to 2018Paul Eggert2018-01-011-1/+1
| | | | Run admin/update-copyright.
* Improve error reporting when serializing non-Unicode strings to JSONPhilipp Stephani2017-12-301-8/+25
| | | | | | | | | | | | | * src/coding.c (utf8_string_p): New helper function. (syms_of_coding) <utf-8-unix>: Move from json.c. * src/json.c (json_check_utf8): New helper function. (lisp_to_json_toplevel_1, lisp_to_json): Use it. To save a bit of time, check for invalid UTF-8 strings only after encountering an error, since Jansson already rejects them. * test/src/json-tests.el (json-serialize/invalid-unicode): Adapt expected error symbol.
* Fix MS-Windows build broken by recent changes in json.cChris Zheng2017-12-251-0/+3
| | | | | | | | * src/json.c [WINDOWSNT] (fn_json_object_get): Define. (init_json_functions) [WINDOWSNT]: Load json_object_get from DLL. (Bug#29848) Copyright-paperwork-exempt: yes
* Accept alists when serializing JSONPhilipp Stephani2017-12-241-10/+47
| | | | | | | | | | | | | * src/json.c (lisp_to_json_toplevel_1): Also accept alists representing objects. * src/json.c (Fjson_serialize): Update docstring. * test/src/json-tests.el (json-serialize/object): Add unit tests for serializing alists. * doc/lispref/text.texi (Parsing JSON): Document that serialization functions accept alists.
* JSON serialization: reject duplicate keys in hashtablesPhilipp Stephani2017-12-241-1/+6
| | | | | | | | * src/json.c (lisp_to_json_toplevel_1): Reject duplicate keys in hashtables. * test/src/json-tests.el (json-serialize/object-with-duplicate-keys): Add unit tests.
* JSON: improve some commentsPhilipp Stephani2017-12-221-5/+8
| | | | | * src/json.c (json_make_string, json_build_string): Document why these functions are OK as-is.
* Define helper functions only if neededPhilipp Stephani2017-12-201-1/+7
| | | | | | * src/json.c (JSON_HAS_ERROR_CODE): New define. (json_parse_error): Use it. (json_has_prefix, json_has_suffix): Define only if needed.
* * src/json.c (json_parse_error): Fix embarrassing bug.Philipp Stephani2017-12-201-0/+3
|
* Use Jansson's error code support if availablePhilipp Stephani2017-12-191-3/+12
| | | | | * src/json.c (json_parse_error): Use Jansson's error code support if available.
* Allow JSON parser functions to return alistsPhilipp Stephani2017-12-191-30/+99
| | | | | | | | | | | | | * src/json.c (Fjson_parse_string, Fjson_parse_buffer): Give these functions a keyword argument to specify the return type for JSON objects. (json_to_lisp): Convert objects to alists if requested. (json_parse_object_type): New helper function to parse keyword arguments. * test/src/json-tests.el (json-parse-string/object): Add a unit test. * doc/lispref/text.texi (Parsing JSON): Document new functionality.
* ; Add a couple of encoding-related FIXMEs to json.cPhilipp Stephani2017-12-191-0/+8
| | | | | | * src/json.c (json_make_string, json_build_string, json_encode) (lisp_to_json_toplevel_1, lisp_to_json): Add FIXMEs for problematic string error reporting.
* ; * src/json.c (lisp_to_json): Inline an unnecessary variable.Philipp Stephani2017-12-191-2/+1
|
* ; Add comments about potential future Jansson flagsPhilipp Stephani2017-12-191-0/+4
| | | | | * src/json.c (Fjson_serialize, Fjson_insert): Add comments about flags that we might potentially add in the future.
* ; * src/json.c: Convert non-ASCII quotes to ASCII characters.Eli Zaretskii2017-12-141-6/+6
|
* Support dynamic loading of libjansson on MS-WindowsEli Zaretskii2017-12-101-0/+181
| | | | | | | | | | | | | | | | | | | | | * src/json.c [WINDOWSNT]: Define fn_* function pointers to jansson functions. (json_delete) [WINDOWSNT]: A wrapper around fn_json_delete, needed by json_decref. (init_json_functions) [WINDOWSNT]: New function. (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer) [WINDOWSNT]: Call init_json_functions if needed, and record JSON in Vlibrary_cache. * src/emacs.c (main): Don't call init_json on WINDOWSNT. * src/w32fns.c (syms_of_w32fns): DEFSYM "json". * lisp/term/w32-win.el (dynamic-library-alist): Add JSON DLL to the list. * configure.ac (HAVE_JSON): Empty JSON_LIBS for MinGW. * nt/INSTALL.W64: * nt/INSTALL: Add information about libjansson.
* Implement native JSON support using JanssonPhilipp Stephani2017-12-101-0/+576
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac: New option --with-json. * src/json.c (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): New defuns. (json_malloc, json_free, json_has_prefix, json_has_suffix) (json_make_string, json_build_string, json_encode) (json_out_of_memory, json_parse_error) (json_release_object, check_string_without_embedded_nulls, json_check) (lisp_to_json, lisp_to_json_toplevel, lisp_to_json_toplevel_1) (json_insert, json_insert_callback, json_to_lisp) (json_read_buffer_callback, Fjson_parse_buffer, define_error): New helper functions. (init_json, syms_of_json): New file. * src/lisp.h: Declaration for init_json and syms_of_json. * src/emacs.c (main): Enable JSON functions. * src/eval.c (internal_catch_all, internal_catch_all_1): New helper functions to catch all signals. (syms_of_eval): Add uninterned symbol to signify out of memory. * src/Makefile.in (JSON_LIBS, JSON_CFLAGS, JSON_OBJ, EMACS_CFLAGS) (base_obj, LIBES): Compile json.c if --with-json is enabled. * test/src/json-tests.el (json-serialize/roundtrip) (json-serialize/object, json-parse-string/object) (json-parse-string/string, json-serialize/string) (json-parse-string/incomplete, json-parse-string/trailing) (json-parse-buffer/incomplete, json-parse-buffer/trailing): New unit tests. * doc/lispref/text.texi (Parsing JSON): New manual section.
* Revert "Implement native JSON support using Jansson"Philipp Stephani2017-09-181-469/+0
| | | | This reverts commit cb99cf5a99680af7dc2c49fdf5b840d1ff4dd928.
* Implement native JSON support using JanssonPhilipp Stephani2017-09-181-0/+469
* configure.ac: New option --with-json. * src/json.c (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): New defuns. (json_out_of_memory, json_parse_error, json_release_object) (check_string_without_embedded_nulls, json_check, lisp_to_json) (json_insert, json_insert_callback, json_to_lisp) (json_read_buffer_callback, Fjson_parse_buffer, define_error): New helper function. (syms_of_json): New file. * src/lisp.h: Declaration for syms_of_json. * src/emacs.c (main): Enable JSON functions. * src/Makefile.in (JSON_LIBS, JSON_CFLAGS, JSON_OBJ, EMACS_CFLAGS) (base_obj, LIBES): Compile json.c if --with-json is enabled. * test/src/json-tests.el (json-serialize/roundtrip) (json-serialize/object, json-parse-string/object): New unit tests.