commit | author | age
|
d6b4a7
|
1 |
## coreJSON Library |
G |
2 |
|
|
3 |
This repository contains the coreJSON library, a parser that strictly enforces the ECMA-404 JSON standard and is suitable for low memory footprint embedded devices. The coreJSON library is distributed under the [MIT Open Source License](LICENSE). |
|
4 |
|
|
5 |
This library has gone through code quality checks including verification that no function has a [GNU Complexity](https://www.gnu.org/software/complexity/manual/complexity.html) score over 8, and checks against deviations from mandatory rules in the [MISRA coding standard](https://www.misra.org.uk). Deviations from the MISRA C:2012 guidelines are documented under [MISRA Deviations](MISRA.md). This library has also undergone both static code analysis from [Coverity static analysis](https://scan.coverity.com/), and validation of memory safety through the [CBMC automated reasoning tool](https://www.cprover.org/cbmc/). |
|
6 |
|
|
7 |
See memory requirements for this library [here](./docs/doxygen/include/size_table.md). |
|
8 |
|
|
9 |
**coreJSON v3.2.0 [source code](https://github.com/FreeRTOS/coreJSON/tree/v3.2.0/source) is part of the [FreeRTOS 202210.00 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202210.00-LTS) release.** |
|
10 |
|
|
11 |
**coreJSON v3.0.0 [source code](https://github.com/FreeRTOS/coreJSON/tree/v3.0.0/source) is part of the [FreeRTOS 202012.00 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202012.00-LTS) release.** |
|
12 |
|
|
13 |
## Reference example |
|
14 |
|
|
15 |
```c |
|
16 |
#include <stdio.h> |
|
17 |
#include "core_json.h" |
|
18 |
|
|
19 |
int main() |
|
20 |
{ |
|
21 |
// Variables used in this example. |
|
22 |
JSONStatus_t result; |
|
23 |
char buffer[] = "{\"foo\":\"abc\",\"bar\":{\"foo\":\"xyz\"}}"; |
|
24 |
size_t bufferLength = sizeof( buffer ) - 1; |
|
25 |
char queryKey[] = "bar.foo"; |
|
26 |
size_t queryKeyLength = sizeof( queryKey ) - 1; |
|
27 |
char * value; |
|
28 |
size_t valueLength; |
|
29 |
|
|
30 |
// Calling JSON_Validate() is not necessary if the document is guaranteed to be valid. |
|
31 |
result = JSON_Validate( buffer, bufferLength ); |
|
32 |
|
|
33 |
if( result == JSONSuccess ) |
|
34 |
{ |
|
35 |
result = JSON_Search( buffer, bufferLength, queryKey, queryKeyLength, |
|
36 |
&value, &valueLength ); |
|
37 |
} |
|
38 |
|
|
39 |
if( result == JSONSuccess ) |
|
40 |
{ |
|
41 |
// The pointer "value" will point to a location in the "buffer". |
|
42 |
char save = value[ valueLength ]; |
|
43 |
// After saving the character, set it to a null byte for printing. |
|
44 |
value[ valueLength ] = '\0'; |
|
45 |
// "Found: bar.foo -> xyz" will be printed. |
|
46 |
printf( "Found: %s -> %s\n", queryKey, value ); |
|
47 |
// Restore the original character. |
|
48 |
value[ valueLength ] = save; |
|
49 |
} |
|
50 |
|
|
51 |
return 0; |
|
52 |
} |
|
53 |
``` |
|
54 |
A search may descend through nested objects when the `queryKey` contains matching key strings joined by a separator, `.`. In the example above, `bar` has the value `{"foo":"xyz"}`. Therefore, a search for query key `bar.foo` would output `xyz`. |
|
55 |
|
|
56 |
## Documentation |
|
57 |
|
|
58 |
For pre-generated documentation, please see the documentation linked in the locations below: |
|
59 |
|
|
60 |
| Location | |
|
61 |
| :-: | |
|
62 |
| [FreeRTOS.org](https://freertos.org/Documentation/api-ref/coreJSON/docs/doxygen/output/html/index.html) | |
|
63 |
|
|
64 |
Note that the latest included version of the coreJSON library may differ across repositories. |
|
65 |
|