Merge pull request #1591 from cesanta/jsondoc

fix JSON docs
This commit is contained in:
Sergey Lyubka authored and GitHub committed 2022-06-15 06:56:08 +01:00
commit 3331ed2f49
1 file changed
+7 -7
+7 -7
View File
@@ -2778,7 +2778,7 @@ mg_json_get_num(mg_str("{\"a\":1.23}", "$.a", &d)); // d contains 1.23
### mg\_json\_get\_bool() ### mg\_json\_get\_bool()
```c ```c
bool mg_json_get_num(struct mg_str json, const char *path, bool *v); bool mg_json_get_bool(struct mg_str json, const char *path, bool *v);
``` ```
Fetch boolean (bool) value from the json string `json` at JSON path Fetch boolean (bool) value from the json string `json` at JSON path
@@ -2795,26 +2795,26 @@ Usage example:
```c ```c
bool b = false; bool b = false;
mg_json_get_num(mg_str("[123]", "$[0]", &b)); // Error. b remains to be false mg_json_get_bool(mg_str("[123]", "$[0]", &b)); // Error. b remains to be false
mg_json_get_num(mg_str("[true]", "$[0]", &b)); // b is true mg_json_get_bool(mg_str("[true]", "$[0]", &b)); // b is true
``` ```
### mg\_json\_get\_str() ### mg\_json\_get\_str()
```c ```c
char *mg_json_get_num(struct mg_str json, const char *path); char *mg_json_get_str(struct mg_str json, const char *path);
``` ```
Fetch string value from the json string `json` at JSON path Fetch string value from the json string `json` at JSON path
`path` into a placeholder `v`. If found, a string is allocated using `calloc()` `path`. If found, a string is allocated using `calloc()`,
un-escaped, and returned to the caller. It is a caller's responsibility to un-escaped, and returned to the caller. It is the caller's responsibility to
`free()` the returned string. `free()` the returned string.
Parameters: Parameters:
- `json` - a string containing valid JSON - `json` - a string containing valid JSON
- `path` - a JSON path. Must start with `$` - `path` - a JSON path. Must start with `$`
Return value: non-NULL on success, NULL or error Return value: non-NULL on success, NULL on error
Usage example: Usage example: