embedded-software
reusable software modules for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JSON Parser

Functions

char * json_find_key (char *key, char *json)
 Parses a JSON string for the string pointed to by key. More...
 
char * json_find_list_item (uint16_t number, char *json)
 for finding the nth list item in the json key More...
 
void json_get_string (char *json, char *mystring)
 This function gets the string associated with a list item from a JSON string. More...
 
unsigned int json_get_int (char *json)
 This function gets the integer associated with a list item from a JSON string. More...
 

Detailed Description

@ brief Helper functions to parse a JSON string in C.

Created on: Apr 14, 2018 Author: Delengowski & Szymczak

Function Documentation

char* json_find_key ( char *  key,
char *  json 
)

Parses a JSON string for the string pointed to by key.

Author
Matt Delengowksi
Date
Apr 14, 2018
Parameters
keyA pointer to a string that is a key within a JSON string
jsonA pointer to the JSON string for which to parse for keys
Returns
Returns the location of the first '[' after the key has been found in json
char* json_find_list_item ( uint16_t  number,
char *  json 
)

for finding the nth list item in the json key

Parameters
numberThe nth list item in the json key
jsonThe json key being passed in
Returns
returns a char pointer, pointing to the nth list item in the json key
unsigned int json_get_int ( char *  json)

This function gets the integer associated with a list item from a JSON string.

Author
Stephen Szymczak
Date
Apr 14, 2018 This function goes through a json string until a ' : ' is found, then checks for and skips spaces. It is assumed the next value after either ':' or ' ' will be a number. The function gets the number. Only unsigned ints are valid (0-65535).
Parameters
jsonA pointer to the JSON string for which to parse for numbers.
Returns
Returns the integer associated with JSON string in question.

Here is the call graph for this function:

void json_get_string ( char *  json,
char *  mystring 
)

This function gets the string associated with a list item from a JSON string.

Author
Stephen Szymczak
Date
Apr 14, 2018 This function goes through a json string until a ' : ' is found, then gets the string following the list item, parsing out the ' " ' at beginning and end. Fills a character array with the desired string.
Parameters
jsonA pointer to the JSON string for which to parse for the string.
mystringA pointer to a user defined string which is populated with the string extraced from json