Skip to content

dict_to_jsonDictToJsonDictToJsondict_to_jsonT_dict_to_json🔗

Short description🔗

dict_to_jsonDictToJsonDictToJsondict_to_jsonT_dict_to_json — Transform a dictionary into a JSON string.

Signature🔗

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

def dict_to_json_s( dict_handle: MaybeSequence[HHandle], gen_param_name: MaybeSequence[str], gen_param_value: MaybeSequence[Union[int, float, str]] ) -> strHerror T_dict_to_json( const Htuple DictHandle, const Htuple GenParamName, const Htuple GenParamValue, Htuple* JsonString )

static HTuple HDict::DictToJson( const HDictArray& DictHandle, const HTuple& GenParamName, const HTuple& GenParamValue )

HString HDict::DictToJson( const HString& GenParamName, const HString& GenParamValue ) const

HString HDict::DictToJson( const char* GenParamName, const char* GenParamValue ) const

HString HDict::DictToJson( const wchar_t* GenParamName, const wchar_t* GenParamValue ) const (Windows only)

static HTuple HDict.DictToJson( HDict[] dictHandle, HTuple genParamName, HTuple genParamValue )

string HDict.DictToJson( string genParamName, string genParamValue )

Description🔗

dict_to_jsonDictToJson transforms the dictionary passed in DictHandledictHandledict_handle into a JSON string and returns that string in JsonStringjsonStringjson_string.

Several optional parameters can be set that control the creation of the JSON strings. Those parameters can be set via GenParamNamegenParamNamegen_param_name and GenParamValuegenParamValuegen_param_value and are described in the documentation of write_dictWriteDict:

  • 'raise_error_if_content_not_serializable'"raise_error_if_content_not_serializable",

  • 'compact_json'"compact_json",

  • 'use_json_arrays'"use_json_arrays".

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

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.

Parameters🔗

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

Dictionary handle.

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: 'compact_json', 'raise_error_if_content_not_serializable', 'use_json_arrays'"compact_json", "raise_error_if_content_not_serializable", "use_json_arrays"

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: 'true', 'false'"true", "false"

JsonStringjsonStringjson_string (output_control) string(-array) → (string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

String in JSON format.

Example🔗

(HDevelop)


dict_to_json (dict{foo: 'bar', bar: [0:2]}, [], [], JSONString)

Result🔗

If the parameters are valid, the operator dict_to_jsonDictToJson returns the value 2 (H_MSG_TRUE). If necessary an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

create_dictCreateDict, read_dictReadDict, json_to_dictJsonToDict

Possible successors

json_to_dictJsonToDict

Alternatives

read_dictReadDict, create_dictCreateDict

See also

json_to_dictJsonToDict, read_dictReadDict, write_dictWriteDict, serialize_handleSerializeHandle, deserialize_handleDeserializeHandle, copy_dictCopyDict

Module🔗

Foundation