{"name": "Leandro","lastName": "Shokida"} {"name": "Mariano","lastName": "De Achaval"}
ndjson
Newline Delimited JSON (ndjson) Format
MIME type: application/x-ndjson
ID: ndjson
DataWeave represents the Newline Delimited JSON format (ndjson) as an array of objects. Each line of the ndjson format is mapped to one object in the array.
The following parser strategies are supported by the ndjson reader:
-
In-memory
-
Streaming
For details, see DataWeave Readers.
Examples
The following examples show uses of the ndjson format.
Example
This example shows how DataWeave represents a simple ndjson input.
Input
Source
The DataWeave script transforms the ndjson input to the DataWeave (dw) format and MIME type.
%dw 2.0
output application/dw
---
payload
dataweave
Output
The DataWeave (dw) format outputs the ndjson input into an array of comma-separated objects.
[ {"name": "Leandro","lastName": "Shokida"}, {"name": "Mariano","lastName": "De Achaval"} ]
weave
Example
This example shows that the ndjson reader ignores all lines of ndjson data that are invalid if skipInvalid=true
.
Input
The input to the DataWeave source includes valid and invalid lines of ndjson data. Assume that the input is from a file myInput.ndjson
.
{"name": "Christian" {"name": "Mariano"} {"name": "Tomo" {"name": "Shoki"}
ndjson
Source
The DataWeave script inputs the contents of the input file myInput.ndjson
, applies the skipInvalid=true
reader property, and transforms the input to the JSON format and MIME type.
%dw 2.0
var myInput = readUrl('classpath://myInput.ndjson', 'application/x-ndjson, {skipInvalid=true})
output application/json
---
myInput
dataweave
Output
The JSON output is an array of the valid objects from the ndjson input.
[ { "name": "Mariano" }, { "name": "Shoki" } ]
weave
Configuration Properties
DataWeave supports the following configuration properties for this format.
Reader Properties
This format accepts properties that provide instructions for reading input data.
Parameter | Type | Default | Description |
---|---|---|---|
|
|
|
Ignores empty lines. Valid values are |
|
|
|
Skips invalid records and ignores values that are not valid in this format. Valid values are |
Writer Properties
This format accepts properties that provide instructions for writing output data.
Parameter | Type | Default | Description |
---|---|---|---|
|
|
|
Size of the buffer writer, in bytes. The value must be greater than |
|
|
|
Generates the output as a data stream when set to Valid values are |
|
|
|
Encoding that the writer uses for output. Defaults to "UTF-8". |
|
|
|
Skips
Valid values are |
|
|
|
Converts attributes of a key into child key-value pairs of that key.
The attribute key name starts with Valid values are |
Supported MIME Types
This format supports the following MIME types.
MIME Type |
---|
|
|