JSON encoder functionality

Updated: October 28, 2024

The encoder API functions let you write JSON objects, arrays, and individual values. You must provide names for all fields, and indicate the start and end of objects and arrays, so the encoder understands the structure of the data being written.

You can start a composite item (object or array) within another composite item, which allows you to nest items. For individual values, you can write the following types:
  • null
  • boolean
  • numeric, including int, long long, and double
  • string, including C-string and JSON-encoded string

There are also functions for inserting whitespace between JSON fields, getting the nesting level and length of the current item, and specifying the data format and encoding options.

To output the data in any encoder you created independently of a decoder, you can obtain a pointer to its JSON string and then write that string to a file, network socket, etc. You can add some or all items in a decoder to such an encoder, which allows you to output JSON data that you read in (and possibly modified).

  翻译: