json
get(dict_inst, key_str)
¶
Return the value based on the key_str
specified.
The following are equivalent::
obj['a']['b']['c'] <=> get(obj, 'a.b.c').value
provided that the keys a
, b
and c
are valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_inst |
Any
|
The dictionary instance to query. |
required |
key_str |
str
|
A simple query to fetch from the dict_inst. |
required |
Returns:
Type | Description |
---|---|
OneOf[Issue, Any]
|
A |
OneOf[Issue, Any]
|
|
Source code in m/core/json.py
jsonq(dict_inst, separator, *key_str)
¶
Stringify the values obtained from multi_get
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_inst |
Mapping[str, Any]
|
The dictionary instance to query. |
required |
separator |
str
|
A string to use to separate the results. |
required |
key_str |
str
|
The queries to apply. |
()
|
Returns:
Type | Description |
---|---|
OneOf[Issue, str]
|
A string separated by |
OneOf[Issue, str]
|
a description of the problems. |
Source code in m/core/json.py
multi_get(dict_inst, *keys)
¶
Call get
for every input specified by keys
.
It collects the invalid keys and returns an Issue
::
multi_get(obj, 'a', 'a.b', 'a.b.c')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_inst |
object
|
The dictionary instance to query. |
required |
keys |
str
|
The queries to apply. |
()
|
Returns:
Type | Description |
---|---|
OneOf[Issue, list[Any]]
|
A |
OneOf[Issue, list[Any]]
|
with the list of failures. |
Source code in m/core/json.py
parse_json(json_str, error_if_empty=False)
¶
Parse a string as json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_str |
str
|
The string to parse. |
required |
error_if_empty |
bool
|
The json parser may throw an error if |
False
|
Returns:
Type | Description |
---|---|
OneOf[Issue, Any]
|
A |
Source code in m/core/json.py
read_json(filename, error_if_empty=False)
¶
Read a json object from a json file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str | None
|
The filename to read from, if |
required |
error_if_empty |
bool
|
The json parser may throw an error if |
False
|
Returns:
Type | Description |
---|---|
OneOf[Issue, Any]
|
A |