Skip to content

Commit

Permalink
Fix formatting and a few omissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin authored Jul 6, 2020
1 parent acd5b81 commit ff3e8ba
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ This function populates the list of children items to a parent array or object.
const char *echttp_json_format (JsonToken *token, int count,
char *json, int size, int options);
```
Format a JSON text give the array of JSON token. The JSON token array is the same that would have been generated by the JSON parser. In fact, this JSON generator is the inverse function of the parser: the generator can consume the output of the parser, while the parser can consume the output of the generator.
Format a JSON text given an array of JSON tokens. The array is the same that would have been generated by the JSON parser. In fact, this JSON format function is the inverse of the parser: the format function can consume the output of the parser, while the parser can consume the output of the format function. The JSON text is written to the json buffer (up to size characters). If options is 0, the JSON text is the most terse possible (no formatting); if options is JSON_OPTION_PRETTY, the JSON text is formatted for readability. The function returns null on success, or an error text on failure.

```
JsonContext echttp_json_start
Expand All @@ -342,7 +342,7 @@ int echttp_json_end (JsonContext context);
const char *echttp_json_export (JsonContext context, char *buffer, int size);
```
This group of functions makes it easy to create JSON data directly from the application. The typical usage is in an HTTP request handler, to build a JSON response to the client's request for live data. The echttp_json_start() function allocates a JSON context used in all subsequent calls. The application provides the JSON token array and a memory pool for storing strings (JSON keys and values). The echttp_json_add_*() functions add one more JSON token to the data structure. The parent argument is used for generating nested structures: a valid parent argument is the return value from a previous call to echttp_json_add_object() or echttp_json_add_array(). The order of the calls must be consistent with the JSON data structure as it defines the order in which the JSON entities will be generated: an object or array must be completely defined before the next non-nested object or array is created. The key argument must be present when the parent is an object, and will be ignored when the parent is an array. The echttp_json_end() function deletes the context and return the count of tokens that have been created. The token array can then be used for create JSON text using echttp_json_format(). Function echttp_json_export() combines echttp_json_end() and echttp_json_format() in a single call (with pretty printing disabled).
This group of functions makes it easy to create JSON data directly from the application. The typical usage is in an HTTP request handler, to build a JSON response to the client's request for live data. The echttp_json_start() function allocates a JSON context used in all subsequent calls. The application provides the JSON token array and a memory pool for storing strings (JSON keys and values). The echttp_json_add_XXX() functions add one more JSON token to the data structure. The parent argument is used for generating nested structures: a valid parent argument is the return value from a previous call to echttp_json_add_object() or echttp_json_add_array(). The order of the calls must be consistent with the JSON data structure as it defines the order in which the JSON entities will be generated: an object or array must be completely defined before the next non-nested object or array is created. The key argument must be present when the parent is an object, and will be ignored when the parent is an array. The echttp_json_end() function deletes the context and return the count of tokens that have been created. The token array can then be used for create JSON text using echttp_json_format(). Function echttp_json_export() combines echttp_json_end() and echttp_json_format() in a single call (with pretty printing disabled).

There are also two JSON utilities provided with echttp:
* echttp_print reformats the content of the JSON files provided and prints it to standard output. By default the output is pretty-printed; if the -r option is used, the output is generated as a single line with no space between JSON elements.
Expand Down

0 comments on commit ff3e8ba

Please sign in to comment.