RPA.JSON
Add items into a JSON serializable object and return the result.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON serializable object |
expr | str | null | JSONPath expression |
value | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | values to either append or update |
If the target is a list, the values are appended to the end. If the target is a dict, the keys are either added or updated.
param doc: | JSON serializable object |
---|---|
param expr: | JSONPath expression |
param value: | values to either append or update |
return: | JSON serializable object of the updated JSON |
Robot Framework Example:
Python Example:
Convert a JSON serializable object to a string and return it.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON serializable object |
param doc: | JSON serializable object |
---|---|
return: | string of the JSON serializable object |
Robot Framework Example:
Python Example:
Convert a string to a JSON serializable object and return it.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | str | null | JSON string |
param doc: | JSON string |
---|---|
return: | JSON serializable object of the string |
Robot Framework Example:
Python Example:
Delete values from a JSON serializable object and return the result. Will delete all values that match the expression.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON serializable object or string |
expr | str | null | JSONPath expression |
param doc: | JSON serializable object or string |
---|---|
param expr: | JSONPath expression |
return: | JSON serializable object with values removed |
Examples
Get a single value from a JSON serializable object that matches the given expression.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON serializable object or string |
expr | str | null | jsonpath expression |
default | Any, None | None | default value to return in the absence of a match |
Raises a ValueError if there is more than one match. Returns the given default argument (or None) if there were no matches.
param doc: | JSON serializable object or string |
---|---|
param expr: | jsonpath expression |
param default: | default value to return in the absence of a match |
return: | string containing the match OR default if there are no matches |
raises ValueError: | |
if more than one match is discovered |
Short Robot Framework Example:
Short Python Example:
Extended Robot Framework Example:
Get all values from a JSON serializable object that match the given expression.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON serializable object or string |
expr | str | null | JSONPath expression |
param doc: | JSON serializable object or string |
---|---|
param expr: | JSONPath expression |
return: | list of values that match |
Short Robot Framework Example:
Short Python Example:
Extended Robot Framework Example:
Load JSON data from a file, and return it as JSON serializable object. Depending on the input file the object can be either a dictionary, a list, or a scalar value.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
filename | str | null | path to input file |
encoding | utf-8 | file character encoding |
param filename: | path to input file |
---|---|
param encoding: | file character encoding |
return: | JSON serializable object of the JSON file |
Examples
Save a JSON serializable object or a string containing a JSON value into a file.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON serializable object or string |
filename | str | null | path to output file |
indent | int, None | None | if given this value is used for json file indent |
encoding | str | utf-8 | file character encoding |
param doc: | JSON serializable object or string |
---|---|
param filename: | path to output file |
param indent: | if given this value is used for json file indent |
param encoding: | file character encoding |
Robot Framework Example:
Python Example:
Update existing values in a JSON serializable object and return the result. Will change all values that match the expression.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
doc | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | JSON or string |
expr | str | null | JSONPath expression |
value | Dict[Hashable, str | int | float | bool | list | dict | None], List[str | int | float | bool | list | dict | None], str, int, float, bool, list, dict, None | null | New value for the matching item(s) |
param doc: | JSON or string |
---|---|
param expr: | JSONPath expression |
param value: | New value for the matching item(s) |
return: | JSON serializable object with updated results |
Short Robot Framework Example:
Extended Robot Framework Example: