Operator Reference

dict_to_jsonT_dict_to_jsonDictToJsonDictToJsondict_to_json (Operator)

dict_to_jsonT_dict_to_jsonDictToJsonDictToJsondict_to_json — Transform a dictionary into a JSON string.

Signature

Herror T_dict_to_json(const Htuple DictHandle, const Htuple GenParamName, const Htuple GenParamValue, Htuple* JsonString)

void DictToJson(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)

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]]) -> str

Description

dict_to_jsondict_to_jsonDictToJsonDictToJsondict_to_json transforms the dictionary passed in DictHandleDictHandleDictHandledictHandledict_handle into a JSON string and returns that string in JsonStringJsonStringJsonStringjsonStringjson_string.

Several optional parameters can be set that control the creation of the JSON strings. Those parameters can be set via GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name and GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value and are described in the documentation of write_dictwrite_dictWriteDictWriteDictwrite_dict:

  • 'raise_error_if_content_not_serializable'"raise_error_if_content_not_serializable""raise_error_if_content_not_serializable""raise_error_if_content_not_serializable""raise_error_if_content_not_serializable",

  • 'compact_json'"compact_json""compact_json""compact_json""compact_json",

  • 'use_json_arrays'"use_json_arrays""use_json_arrays""use_json_arrays""use_json_arrays".

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

Execution Information

  • Multithreading type: independent (runs in parallel even with exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

Parameters

DictHandleDictHandleDictHandledictHandledict_handle (input_control)  dict(-array) HDict, HTupleMaybeSequence[HHandle]HTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Dictionary handle.

GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name (input_control)  attribute.name(-array) HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)

Name of the generic parameter.

Default: []

List of values: 'compact_json'"compact_json""compact_json""compact_json""compact_json", 'raise_error_if_content_not_serializable'"raise_error_if_content_not_serializable""raise_error_if_content_not_serializable""raise_error_if_content_not_serializable""raise_error_if_content_not_serializable", 'use_json_arrays'"use_json_arrays""use_json_arrays""use_json_arrays""use_json_arrays"

GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value (input_control)  attribute.name(-array) HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)

Value of the generic parameter.

Default: []

Suggested values: 'true'"true""true""true""true", 'false'"false""false""false""false"

JsonStringJsonStringJsonStringjsonStringjson_string (output_control)  string(-array) HTupleSequence[str]HTupleHtuple (string) (string) (HString) (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_jsondict_to_jsonDictToJsonDictToJsondict_to_json returns the value 2 ( H_MSG_TRUE) . If necessary an exception is raised.

Possible Predecessors

create_dictcreate_dictCreateDictCreateDictcreate_dict, read_dictread_dictReadDictReadDictread_dict, json_to_dictjson_to_dictJsonToDictJsonToDictjson_to_dict

Possible Successors

json_to_dictjson_to_dictJsonToDictJsonToDictjson_to_dict

Alternatives

read_dictread_dictReadDictReadDictread_dict, create_dictcreate_dictCreateDictCreateDictcreate_dict

See also

json_to_dictjson_to_dictJsonToDictJsonToDictjson_to_dict, read_dictread_dictReadDictReadDictread_dict, write_dictwrite_dictWriteDictWriteDictwrite_dict, serialize_handleserialize_handleSerializeHandleSerializeHandleserialize_handle, deserialize_handledeserialize_handleDeserializeHandleDeserializeHandledeserialize_handle, copy_dictcopy_dictCopyDictCopyDictcopy_dict

Module

Foundation