Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JsonConverter

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

Example

let value1 = JsonConverter.fromJson("{\"key\":123}"); // Result: { key: 123 }
let value2 = JsonConverter.toMap({ key: 123}); // Result: "{\"key\":123}"
see

TypeCode

Hierarchy

  • JsonConverter

Index

Methods

Static fromJson

  • fromJson<T>(type: TypeCode, value: string): T
  • Converts JSON string into a value of type specified by a TypeCode.

    Type parameters

    • T

    Parameters

    • type: TypeCode

      the TypeCode for the data type into which 'value' is to be converted.

    • value: string

      the JSON string to convert.

    Returns T

    converted object value or null when value is null.

Static toJson

  • toJson(value: any): string
  • Converts value into JSON string.

    Parameters

    • value: any

      the value to convert.

    Returns string

    JSON string or null when value is null.

Static toMap

  • toMap(value: string): any
  • Converts JSON string into map object or returns empty map when conversion is not possible.

    see

    toNullableMap

    Parameters

    • value: string

      the JSON string to convert.

    Returns any

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

Static toMapWithDefault

  • toMapWithDefault(value: string, defaultValue: any): any
  • Converts JSON string into map object or returns default value when conversion is not possible.

    see

    toNullableMap

    Parameters

    • value: string

      the JSON string to convert.

    • defaultValue: any

      the default value.

    Returns any

    Map object value or default when conversion is not supported.

Static toNullableMap

  • toNullableMap(value: string): any
  • Converts JSON string into map object or returns null when conversion is not possible.

    see

    MapConverter.toNullableMap

    Parameters

    • value: string

      the JSON string to convert.

    Returns any

    Map object value or null when conversion is not supported.

Generated using TypeDoc