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.
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).