The library currently offers three features, a getter and setter accepting a javascript format string representing the syntax, and two functions reading/writing JSON to a file.
The library currently offers four features, a getter, a setter and a deleter function, accepting a javascript format string representing the syntax, and two functions for reading/writing JSON to a file.
### Setter
### Setter
The setter function, ```json_object_set_by_string_delimiter(5)```, takes five arguments, albeit with recommended to be used through a wrapper function ```json_object_set_by_string(4)```, defaulting the delimiter to a dot,```.```.
The setter function, ```json_object_set_by_string_delimiter(5)```, will set a value based on provided format, taking five arguments, albeit recommended to be used through a wrapper function ```json_object_set_by_string(4)```, defaulting the delimiter to a dot,```.```.
```src``` is a pointer to the address of a ```struct json_object```, if it is a null pointer an object will be created.
#### Arguments
```fmt``` is a string representing the syntax pointing to the object to be set, i.e. ```device.macaddr```, note that this syntax may contain nested objects or arrays without restrictions, i.e. ```a.b[1][0].c```. Additionally, if a key, array or index is missing it will be created and added to the ```src``` pointer. *NULL represents root key.*
```val``` represents the value to be set. This should always be presented in a string format, albeit can be used to represent integers, strings, arrays of object depending on syntax, i.e. ```{\"macaddr\":\"11:22:33:44:55:66\"}```.
1.```src``` is a pointer to the address of a ```struct json_object```, if it is a null pointer an object will be created.
```type``` expects an enum of ```json_type```, to declare as what object type the input should be added.
2.```fmt``` is a string representing the syntax pointing to the object to be set, i.e. ```device.macaddr```, note that this syntax may contain nested objects or arrays, i.e. ```a.b[1][0].c```. Additionally, if a key, array or index is missing it will be created and added to the ```src``` pointer. *NULL represents root key.*
```delimiter``` is syntactical delimiter in the format string.
3.```val``` represents the value to be set. This should always be presented in a string format, albeit can be used to represent integers, strings, arrays of object depending on syntax, i.e. ```{\"macaddr\":\"11:22:33:44:55:66\"}```.
4.```type``` expects an enum of ```json_type```, to declare as what object type the input should be added.
5.```delimiter``` is syntactical delimiter in the format string.
#### Example usage
#### Example usage
...
@@ -52,15 +55,18 @@ For more example usage see ```test/api_test.c```.
...
@@ -52,15 +55,18 @@ For more example usage see ```test/api_test.c```.
### Getter
### Getter
The getter function, ```json_object_get_by_string_delimiter(3)```, similarily to the setter, takes five arguments, recommended to be used through a wrapper function ```json_object_get_by_string(2)```, defaulting the delimiter to a dot,```.```. If the specified format is not present in the object NULL is returned.
The getter function, ```json_object_get_by_string_delimiter(3)```, gets a key or value based on provided format. Like the setter, recommended to be used through a wrapper function ```json_object_get_by_string(2)```, defaulting the delimiter to a dot,```.```. If the specified format is not present in the object NULL is returned.
```src``` is a pointer to the ```struct json_object``` to traverse.
#### Arguments
```fmt``` is a string representing the syntax pointing to the object to be set, i.e. ```device.macaddr```, note that this syntax may contain nested objects or arrays without restrictions, i.e. ```a.b[1][0].c```.
```delimiter``` is syntactical delimiter in the format string.
1.```src``` is a pointer to the ```struct json_object``` to traverse.
2.```fmt``` is a string representing the syntax pointing to the object to be set, i.e. ```device.macaddr```, note that this syntax may contain nested objects or arrays, i.e. ```a.b[1][0].c```.
3.```delimiter``` is syntactical delimiter in the format string.
#### Example usage
#### Example usage
...
@@ -79,6 +85,41 @@ Will return an json object containing ```1```.
...
@@ -79,6 +85,41 @@ Will return an json object containing ```1```.
For more example usage see ```test/api_test.c```.
For more example usage see ```test/api_test.c```.
### Deleter
The deleter function, ```json_object_del_by_string_delimiter(3)```, deletes a value based on provided format, recommended to be used through the wrapper function ```json_object_del_by_string(2)```, defaulting the delimiter to a dot,```.```. If the specified format is not present in the object NULL is returned.
```
int json_object_del_by_string(struct json_object *src, char *fmt);
int json_object_del_by_string_delimiter(struct json_object *src, char *fmt, const char *delimiter);
```
#### Arguments
```src``` is a pointer to the ```struct json_object``` to traverse.
```fmt``` is a string representing the syntax pointing to the object to be set, i.e. ```device.macaddr```, note that this syntax may contain nested objects or arrays, i.e. ```a.b[1][0].c```.
```delimiter``` is syntactical delimiter in the format string.