Table of Contents

Search

  1. Preface
  2. The Transformation Language
  3. Constants
  4. Operators
  5. Variables
  6. Dates
  7. Functions

Transformation Language Reference

Transformation Language Reference

PARSE_JSON

PARSE_JSON

Parses JSON hierarchical data in a string data type and generates a struct. The struct schema is based on the specified complex data type definition that you pass in the argument. This function is appropriate when you receive hierarchical data midstream in the mapping, and need to parse the data for downstream processing.

Syntax

PARSE_JSON(upstream_string,:Type.type_definition_library.type_definition)
The following table describes the arguments for this command:
Argument
Required/Optional
Description
upstream_string
Required
The source string field, midstream in the mapping, that contains hierarchical data in JSON format.
:Type.type_definition_library.type_definition
Required
The complex data type definition that represents the schema of the struct data.
Use the reference qualifier
:Type
to reference the type definition library that contains the complex data type definition.

Return Value

Struct.

Examples

The following expression generates a struct based on the specified complex data type definition
customer_def
.
PARSE_JSON(upstream_string,:Type.type_definition_library.customer_def)
The following example shows JSON data in the upstream fields, assigned as a string data type:
{"customer" : "ABC Co", "contract" : "1010", "city" : "Phoenix", "saleamt" : "150000.00"} {"customer" : "Data Inc", "contract" : "1111", "city" : "Portland", "saleamt" : "20000.00"}
The complex data type definition
customer_def
is defined in the type definition library as follows:
customer_def{ customer : string contract : int city : string saleamt : int }
The following table shows how the PARSE_JSON function in the mapping expression parses the upstream string using
customer_def
and returns a struct:
customer
contract
city
saleamt
RETURN VALUE
ABC Co
1010
Phoenix
150000.00
{ customer:ABC Co contract:1010 city:Phoenix saleamt:150000.00 }
Data Inc
1111
Portland
20000.00
{ customer:Data Inc contract:1111 city:Portland saleamt:20000.00 }

0 COMMENTS

We’d like to hear from you!