pip_services3_commons.convert.JsonConverter module

pip_services3_commons.convert.JsonConverter

Json conversion utilities

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.convert.JsonConverter.JsonConverter

Bases: object

Converts arbitrary values from and to JSON (JavaScript Object Notation) strings.

Example:

value1 = JsonConverter.from_json("{"key":123}") // Result: { key: 123 }
value2 = JsonConverter.to_map({ key: 123}) // Result: "{"key":123}"
static from_json(typ: pip_services3_commons.convert.TypeCode.TypeCode, value: str) → Any

Converts JSON string into a args.

Parameters
  • typ – the TypeCode for the data type into which ‘args’ is to be converted.

  • value – the JSON string to convert.

Returns

converted object args or null when args is None.

static to_json(value: Any) → Optional[str, None]

Converts args into JSON string.

Parameters

value – the args to convert.

Returns

JSON string or null when args is None.

static to_map(value: str) → Any

Converts JSON string into map object or returns empty map when conversion is not possible.

Parameters

value – the JSON string to convert.

Returns

Map object args or empty object when conversion is not supported.

static to_map_with_default(value: str, default_value: Any) → Any

Converts JSON string into map object or returns default args when conversion is not possible.

Parameters
  • value – the JSON string to convert.

  • default_value – the default args.

Returns

Map object args or default when conversion is not supported.

static to_nullable_map(value: str) → Any

Converts JSON string into map object or returns null when conversion is not possible.

Parameters

value – the JSON string to convert.

Returns

Map object args or null when conversion is not supported.