Skip to content

json_to_dictJsonToDictJsonToDictjson_to_dictT_json_to_dict🔗

Short description🔗

json_to_dictJsonToDictJsonToDictjson_to_dictT_json_to_dict — Transform a JSON string into a dictionary.

Signature🔗

json_to_dict( string JsonString, attribute.name GenParamName, attribute.name GenParamValue, out dict DictHandle )void JsonToDict( const HTuple& JsonString, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DictHandle )static void HOperatorSet.JsonToDict( HTuple jsonString, HTuple genParamName, HTuple genParamValue, out HTuple dictHandle )def json_to_dict( json_string: MaybeSequence[str], gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> Sequence[HHandle]

def json_to_dict_s( json_string: MaybeSequence[str], gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> HHandleHerror T_json_to_dict( const Htuple JsonString, const Htuple GenParamName, const Htuple GenParamValue, Htuple* DictHandle )

static HDictArray HDict::JsonToDict( const HTuple& JsonString, const HTuple& GenParamName, const HTuple& GenParamValue )

void HDict::JsonToDict( const HString& JsonString, const HString& GenParamName, const HString& GenParamValue )

void HDict::JsonToDict( const char* JsonString, const char* GenParamName, const char* GenParamValue )

void HDict::JsonToDict( const wchar_t* JsonString, const wchar_t* GenParamName, const wchar_t* GenParamValue ) (Windows only)

static HDict[] HDict.JsonToDict( HTuple jsonString, HTuple genParamName, HTuple genParamValue )

void HDict.JsonToDict( string jsonString, string genParamName, string genParamValue )

Description🔗

json_to_dictJsonToDict transforms the string passed in JsonStringjsonStringjson_string, which must be valid JSON, into a dictionary and returns the handle of the dictionary in DictHandledictHandledict_handle.

Several optional parameters can be set that control the values of JSON constants. Those parameters can be set via GenParamNamegenParamNamegen_param_name and GenParamValuegenParamValuegen_param_value and are described in the documentation of read_dictReadDict.

json_to_dictJsonToDict can transform several strings at once. For this, JsonStringjsonStringjson_string must contain a tuple of strings. The output DictHandledictHandledict_handle will then contain one dictionary per input string.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.

Parameters🔗

JsonStringjsonStringjson_string (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

String in JSON format.

Default: ['{"key": "value"}']["{"key": "value"}"]

GenParamNamegenParamNamegen_param_name (input_control) attribute.name(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Name of the generic parameter.

Default: [][]
List of values: 'convert_json_arrays_to', 'json_value_false', 'json_value_null', 'json_value_true'"convert_json_arrays_to", "json_value_false", "json_value_null", "json_value_true"

GenParamValuegenParamValuegen_param_value (input_control) attribute.name(-array) → (string / integer / real)HTuple (HString / Hlong / double)HTuple (string / int / long / double)MaybeSequence[Union[int, float, str]]Htuple (char* / Hlong / double)

Value of the generic parameter.

Default: [][]
Suggested values: 0, 1, 'HNULL', 'true', 'false', 'dict', 'tuple', 'tuple_if_possible'0, 1, "HNULL", "true", "false", "dict", "tuple", "tuple_if_possible"

DictHandledictHandledict_handle (output_control) dict(-array) → (handle)HTuple (HHandle)HDict, HTuple (IntPtr)Sequence[HHandle]Htuple (handle)

Dictionary handle.

Example🔗

(HDevelop)


json_to_dict ('{"capacity": "medium", "image_height": 1024, "image_width": 1024}', [], [], DictHandle)

Result🔗

If the parameters are valid, the operator json_to_dictJsonToDict returns the value 2 (H_MSG_TRUE). If necessary an exception is raised. This is especially the case if JsonStringjsonStringjson_string does not contain valid JSON.

Combinations with other operators🔗

Combinations

Possible successors

write_dictWriteDict, copy_dictCopyDict

Alternatives

read_dictReadDict, create_dictCreateDict

See also

read_dictReadDict, write_dictWriteDict, serialize_handleSerializeHandle, deserialize_handleDeserializeHandle

Module🔗

Foundation