summaryrefslogtreecommitdiff
path: root/json-glib/json-generator.c
Commit message (Collapse)AuthorAgeFilesLines
* generator: ensure valid output double exponential notationMark Nauwelaerts2023-01-261-1/+6
| | | | Fixes #67
* Drop or mark unused parametersEmmanuele Bassi2022-10-111-3/+1
| | | | Avoid compiler warnings when running with `-Wunused-parameter`.
* Update the JsonGenerator documentationEmmanuele Bassi2021-06-101-34/+35
|
* Merge branch 'gidocgen' into 'master'Emmanuele Bassi2021-06-081-41/+44
|\ | | | | | | | | Use gi-docgen to build the API reference See merge request GNOME/json-glib!41
| * docs: Initial, rough port away from gtk-docEmmanuele Bassi2021-06-081-41/+44
| | | | | | | | | | | | | | | | | | | | Drop `SECTION` blurbs. Use gi-docgen syntax for internal links. Use summary lines for gi-docgen indices. Use Markdown syntax for code fragments.
* | trivial: Return the correct type in g_return_val_if_fail()wip/hughsie/typecheckRichard Hughes2021-05-161-1/+1
|/
* Gracefully handle empty arrays and objectsEmmanuele Bassi2020-08-241-5/+9
| | | | | | Don't pretty print newlines. This requires a change in the generator test, but the pretty printing format is not stable anyway, so we can get away with it.
* generator: Add an GString-based methodGarrett Regier2017-06-161-11/+30
| | | | | | This allows callers to avoid extra allocations when dumping to a preexisting string. https://bugzilla.gnome.org/show_bug.cgi?id=773504
* core: Avoid json_object_get_members()Garrett Regier2017-06-161-5/+4
| | | | | | | Use JsonObject's private members_ordered GQueue instead. This avoids a g_list_copy(). https://bugzilla.gnome.org/show_bug.cgi?id=773504
* introspection: fix nullable annotation for return values in the following ↵Alberto Ruiz2017-03-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | methods json_builder_add_boolean_value json_builder_add_double_value json_builder_add_int_value json_builder_add_null_value json_builder_add_string_value json_builder_add_value json_builder_begin_array json_builder_begin_object json_builder_end_array json_builder_end_object json_builder_get_root json_builder_set_member_name json_generator_get_root json_reader_get_error json_reader_get_member_name json_reader_get_value json_serializable_find_property json_serializable_find_property json_boxed_serialize
* generator: Avoid multiple buffer allocationsGarrett Regier2017-03-181-187/+67
| | | | | | | Instead share a single GString in all dump functions. https://bugzilla.gnome.org/show_bug.cgi?id=773504
* Don't loose decimal in whole-double -> string conversiondjcb2017-03-131-0/+5
| | | | | | | | | | | | | When converting json to its string representation, whole-doubles (such as 1.0) would be converted into strings without decimals ("1"). That can be inconvenient e.g. when converting from/to GVariants. To avoid this, append '.0' to the string representation for doubles if they lost their decimals in the conversion. Also add / update unit tests for this. https://bugzilla.gnome.org/show_bug.cgi?id=753763
* Stop providing our own marshaller and use the generic oneThibault Saunier2017-03-131-2/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=773603
* node: Add json_node_ref() and json_node_unref()Philip Withnall2016-03-011-2/+2
| | | | | | | | | | | | | | Add reference counting semantics to JsonNode, in addition to the existing init/unset and alloc/free semantics. json_node_free() must only be used with nodes allocated using json_node_alloc(). json_node_unref() may be used with all nodes (if correctly paired; it may be paired with json_node_alloc()). It is not valid to call json_node_free() on a node whose reference count is not 1. https://bugzilla.gnome.org/show_bug.cgi?id=756121
* generator: Escape the control characters correctlyStef Walter2014-05-211-26/+47
| | | | | | | Escaping these as octals is out of the JSON spec completely, so roll our own string encoder. https://bugzilla.gnome.org/show_bug.cgi?id=730425
* generator: Escape Object key names correctlyStef Walter2014-05-201-8/+11
| | | | | | Also fix empty keys, which are now encoded properly. https://bugzilla.gnome.org/show_bug.cgi?id=727593
* Remove conditional inclusion of config.hEmmanuele Bassi2014-03-181-2/+0
| | | | All the platforms and build system we support have a config.h header.
* docs: Port to MarkDownEmmanuele Bassi2014-03-181-3/+6
| | | | | Drop the DocBook documentation, and move everything to the MarkDown format used by modern gtk-doc.
* Drop some more pointless GET_PRIVATE macrosEmmanuele Bassi2013-08-221-6/+5
| | | | We can use the autogenerated get_instance_private() function.
* Remove compile time GLib version checkEmmanuele Bassi2013-08-211-13/+1
| | | | | We depend on a new version of GLib, so we can remove a bunch of old version checks.
* Use new macros when compiling against new GLibEmmanuele Bassi2013-07-201-3/+12
| | | | | | | | If we're being compiled against a newer version of GLib, we should use the new macros that add instance private data. Since this is a stable branch, we cannot bump the GLib requirement; so we use version checks to conditionally compile the new code.
* generator: Use JsonValue, not GValueEmmanuele Bassi2012-07-151-15/+18
| | | | | We don't need to turn a JsonValue into a GValue, given that we only care about the JSON types when serializing to JSON.
* generator: Removes blank spaces from generated JSON when not pretty-printEduardo Lima Mitev2011-03-111-12/+23
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=640729
* generator: Use g_ascii_dtostr() to avoid losing precisionEmmanuele Bassi2011-01-101-3/+4
| | | | | | | The nice format escape for g_ascii_formatd() is not really suited for a serialization format, as it obviously loses precision. https://bugzilla.gnome.org/show_bug.cgi?id=637244
* generator: Clean up and add accessorsEmmanuele Bassi2010-12-141-43/+213
| | | | | | | | Instead of asking everyone to use g_object_set() to set up a JsonGenerator the class should provide a decent API for its properties. While we're at it, we should also use modern API for installing and notifying of property changes.
* generator: Implement dumping bare valuesEmmanuele Bassi2010-12-141-5/+10
| | | | | JsonGenerator is not able to generate strings for bare values, something that completely went under the radar for all this time.
* generator: Add an OutputStream-based methodEmmanuele Bassi2010-08-021-0/+37
| | | | | | | Currently, only synchronous API. The output handling is pretty trivial, unlike the input handling in JsonParser; this is a really basic convenience API.
* generator: Use %g format for g_ascii_formatd()Emmanuele Bassi2010-03-181-1/+1
| | | | | | | | | | | I should read the documentation for the functions I use: Converts a gdouble to a string, using the '.' as decimal point. To format the number you pass in a printf()-style format string. Allowed conversion specifiers are 'e', 'E', 'f', 'F', 'g' and 'G'. -- from g_ascii_formatd() in GLib's API reference Epic reading fail.
* Doubles are converted to strings containing commasCornelius Hald2009-11-121-1/+6
| | | | | | | | | | | | Under some locales (e.g. de_DE) a double is converted to a string containing a comma instead of a dot. That breaks the JSON syntax. Example: Double: 0.34 is converted to 0,34 when using locale de_DE http://bugzilla.openedhand.com/show_bug.cgi?id=1826 Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
* [docs] Small documentation fixesEmmanuele Bassi2009-09-021-5/+6
| | | | Clean up some notes, and add introspection annotations where needed.
* Auto-promote integer types to G_TYPE_INT64Emmanuele Bassi2009-08-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The JSON RFC does not specify the size of the integer type, thus implicitly falling back to machine-size. This would all be fine and dandy if some demented Web Developer (and I use the term "developer" *very much* loosely) did not decide to use integers to store unique identifiers for objects; obviously, you can't have more than 2^32-1 status messages in a database with millions of users who update their status multiple times per day. Right, Twitter? Anyway, some languages do a type auto-promotion from Integer to Long, thus pushing the limit of allowed positive values -- until the next integer overflow, that is. C, and GLib, do not do that transparently for us so we need to: - always use gint64 when parsing a JSON data stream using JsonScanner - move all the Node, Object and Array APIs to gint64 - auto-promote G_TYPE_INT to G_TYPE_INT64 when setting a GValue manually - auto-promote and auto-demote G_TYPE_INT properties when (de)serializing GObjects. The GLib types used internally by JSON-GLib are, thus: integer -> G_TYPE_INT64 boolean -> G_TYPE_BOOLEAN float -> G_TYPE_DOUBLE string -> G_TYPE_STRING
* [generator] Pre-compute the escape tableEmmanuele Bassi2009-06-211-10/+33
| | | | | | | | | | | Instead of allocating the escape table to be used with g_strescape() for each string we can have it unrolled already in code. Thanks to: Christian Persch <chpe@gnome.org> Fixes bug: http://bugzilla.openedhand.com/show_bug.cgi?id=1648
* Fix license and copyright noticesEmmanuele Bassi2009-06-091-2/+6
| | | | | | | | THere is no such thing as the "Lesser General Public License version 2": the LGPL v2 is the "Library GPL", and has been superceded by v2.1 with the new "Lesser GPL" name. Also, the copyright is now Intel Corp.
* [node] Make JsonNode completely privateEmmanuele Bassi2009-06-091-0/+2
| | | | | | | | | | The JsonNode structure has always been meant to be completely opaque; we indirectly exposed the :type member, but only for access through the JSON_NODE_TYPE() macro. Since that macro has become a proxy for the json_node_get_node_type() function we can safely move everything into a private, uninstalled header file and let JsonNode be completely opaque to the developer.
* Fix a variable shadowingEmmanuele Bassi2008-06-131-1/+2
|
* Escape to special characters in JsonGeneratorbug-958Emmanuele Bassi2008-06-131-1/+16
| | | | | | | | | | | | When using json-glib to write a blog system, some deserialized objects were not been interpreted by javascript because there were line breaks in generated strings. Patch from Lincoln de Sousa. Bug #958 - JsonGenerator does not escape special characters Signed-off-by: Emmanuele Bassi <ebassi@openedhand.com>
* Wrap config.h include with conditionalsEmmanuele Bassi2007-12-251-0/+2
| | | | | Including the autotools generated config.h should always be conditional on the HAVE_CONFIG_H definitions.
* Do not leak the intermediate strings when generating JSONEmmanuele Bassi2007-12-251-0/+6
| | | | Found this very dumb leak while using Valgrind.
* Use a unicode character for the indent-char property of JsonGeneratorEmmanuele Bassi2007-11-211-8/+8
| | | | | The indent character should be any Unicode character available instead of a generic char.
* Add the indent-char property to JsonGeneratorEmmanuele Bassi2007-11-211-14/+40
| | | | | The JsonGenerator:indent-char can be used to control the character that indents the lines when pretty printing.
* Use G_TYPE_DOUBLE when dumping a value.Emmanuele Bassi2007-11-211-2/+2
| | | | | JsonNode of type value for floating point numbers is G_TYPE_DOUBLE and not G_TYPE_FLOAT anymore.
* Add the JsonGenerator:root propertyEmmanuele Bassi2007-11-131-2/+28
| | | | | | | | | | | | | | | | JsonGenerator now has a :root property, so it can be constructed using just g_object_new(): generator = g_object_new (JSON_TYPE_GENERATOR, "pretty", TRUE, "indent", 4, "root", node, NULL); This means that the root node is copied inside the generator, instead of just taking ownership (it was quite confusing). The documentation now clearly states what happens, and that you can safely free the node after feeding it to the JsonGenerator.
* Fix the compiler fixesEmmanuele Bassi2007-10-161-4/+6
| | | | | This is what happens when you fix a compiler warning about a shadowing variable and you don't run the test suite to check the results.
* Fix compilation errors with extra maintainer CFLAGSEmmanuele Bassi2007-10-161-8/+8
|
* Add objects supportEmmanuele Bassi2007-10-021-3/+122
| | | | | JsonGenerator can now create objects and array-nested objects, with and without pretty printing. The test suite has been updated accordingly.
* Add nested arrays supportEmmanuele Bassi2007-10-011-0/+10
| | | | | JsonGenerator now supports nested arrays, both with and without pretty printing. The tests suite has been updated accordingly.
* Simple arrays generationEmmanuele Bassi2007-10-011-5/+155
| | | | | | | JsonGenerator now can create simple arrays, with "pretty" enabled and disabled. Simple arrays are just one-level, value-only arrays. The test unit has been updated to exercise this new feature.
* Move data types ctors and setters into the public headersEmmanuele Bassi2007-10-011-1/+0
| | | | | | | Now that we are providing a generator class we need to provide the constructors and setters for JsonNode, JsonObject and JsonArray. This also means that the json-private.h header is now useless, so we can remove it from the build and repository.
* Add stub class for JsonGeneratorEmmanuele Bassi2007-10-011-0/+255
JsonGenerator is an object that creates JSON data streams from a data model tree. This commit adds the JsonGenerator class to the build and API reference.