JSONEncode - Convert to JSON

Input stream can be converted into the JSON string.
About what kind of the JSON format can be converted to, please refer to "How to Convert".

Stream Information

InputFormatCSV,FixedLength,XML,ParameterList,Record
Number of Inputs1
DescriptionCSV, FixedLength, XML, ParameterList, Record stream can be input. Stream container can't be received.
OutputFormatText
DescriptionConvert the input stream to the JSON string and output it.

Component Properties

NameData TypeMappingDescription
IndentbooleanOut Specify whether to indent or not.
true [true] - Indent.
false [false] - Don't indent.
JSONRecordObjectNamechoiceIn & Out When the input stream is CSV, Record or FixedLength, specify the top level name of the JSON object. Value can be input directly.
If "(none)" is specified, the input stream will be output as an array.
About the description, please refer to "How to Convert" as below.
record [SystemDefault] - Output with the {"record":[ ... ]} format.
(none) [ONLY_JSONArray] - Output with the [ ... ] format.
IgnoreNamespacePrefixbooleanOut When the input stream is XML, specify whether to delete the namespace prefix or not.
true [true] - Delete.
false [false] - Don't delete.
OmitRootElementbooleanOut When the input stream is XML, specify whether to delete the root element or not.
true [true] - Delete.
false [false] - Don't delete.

Loop

This component doesn't loop.

Transaction

CommitDo nothing
RollbackDo nothing

Exceptions

TypeParameterStream for error handling flowError
Code
Description
Exception None This component's input stream1The input stream type isn't CSV, FixedLength, XML, ParameterList or Record.
2Can't be converted to the JSON string.

How to Convert

Input stream can be converted as below with each format.

Record, CSV, FixedLength

When the JSONRecordObjectName property is set to "record", an array will be created with the "record" key on the top level. An array element is an object which takes each record's field name as a key. If the value except "record" is assigned, the assigned value can be a top level key.

{ "record":[
    { "field1": "aaa", "field2": 1, "field3": true},
    { "field1": "bbb", "field2": 2, "field3": false},
    { "field1": "ccc", "field2": 3, "field3": true}]
}

When the JSONRecordObjectName property is specified to "(none)", an array which doesn't have a key in the top level will be created. An array element is an object which takes each record's field name as a key.

[
    { "field1": "aaa", "field2": 1, "field3": true},
    { "field1": "bbb", "field2": 2, "field3": false},
    { "field1": "ccc", "field2": 3, "field3": true}
]

ParameterList

Take a field name as a key, and each field value is output to the top level.

{ 
  "field1": "aaa",
  "field2": ["aaa", "bbb", "ccc"],
  "field3": 10
}

XML

Convert the input stream into json object according to the following rules and XML structure.

1) Example of XML before conversion

<root>
    <record attr1="1">
    	<element1>aaa</element1>
    </record>
    <record attr1="2">
    	<element1>bbb</element1>
    </record>
</root>

JSON string after conversion

{ "root": {
    "record": [
      {
        "attr1": "1",
        "element1": "aaa"
      },
      {
        "attr1": "2",
        "element1": "bbb"
      }
    ]}
}

2) Example of XML before conversion (When there is a namespace, IgnoreNamespacePrefix is specified to "true", and the property is same as the element name)

<root xmlns:fs="http://www.example.com/">
    <fs:record fs:id="1">
    	<fs:name>aaa</fs:name>
    	<fs:id>1-1</fs:id>
    	<fs:id>1-2</fs:id>
    </fs:record>
    <fs:record id="2">
    	<fs:name>aaa</fs:name>
    	<fs:id>2-1</fs:id>
    	<fs:id>2-2</fs:id>
    </fs:record>
</root>

JSON string after conversion

{ "root": {
    "record": [
      {
        "id": "1",
        "name": "aaa",
        "id": ["1-1", "1-2"]
      },
      {
        "id": "2",
        "name": "aaa",
        "id": ["2-1", "2-2"]
      }
    ]}
}

Binary, Text, HTML, MIME

These streams can't be converted to JSON.

About Data Type