Stream JSON File Reader

Discover more about the Stream JSON File Reader component and how to use it on the Digibee Integration Platform.

Stream JSON File Reader reads a local JSON file, applies a JSON Path expression, returns a JSON structure according to the defined expressions and triggers subpipelines to process each message. The component is to be used for large files.

Parameters

Take a look at the configuration parameters of the component. Parameters supported by Double Braces expressions are marked with (DB).

Parameter
Description
Default value
Data type

File Name (DB)

File name or full file path (i.e. tmp/processed/file.json) of the local JSON file.

data.json

String

JSON Path

JSON Path expression that determines how the JSON file stream reading will occur.

$

String

Element Identifier

Attribute that will be sent in case of errors.

data

String

Parallel Execution Of Each Iteration

Occurs in parallel with the loop execution.

False

Boolean

Fail On Error

When active, this parameter suspends the pipeline execution if there’s a severe occurrence in the iteration structure, disabling its complete conclusion.

The Fail On Error parameter activation doesn’t have any connection with the errors occurred in the components used for the construction of the subpipelines (onProcess and onException).

False

Boolean

Messages flow

Input

No specific input message is expected, but the existence of a JSON file in the pipeline local directory and the filling of the File Name and JSON Path fields for the file processing.

Output

{
"total": 0,
"success": 0,
"failed": 0
}
  • total: total number of processed lines.

  • success: total number of successfully processed lines.

  • failed: total number of lines whose process failed.

When the lines are correctly processed, their respective subpipelines return { "success": true } for each of them.

The component throws an exception if the File Name doesn’t exist or can’t be read.

The files manipulation inside a pipeline occurs in a protected way. All the files can be accessed with a temporary directory only, where each pipeline key gives access to its own files set.

Stream JSON File Reader makes batch processing. To better understand the concept, read the article about Batch processing.

Stream JSON File Reader in action

Making the file stream with no filters in JSON Path

Input

  • file.json

{
"products" : [
{
"product": "Chair",
"price": 20.75,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "TV",
"price": 399.99,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "Couch",
"price": 100,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "Table",
"price": 78.99,
"tags": ["NEW", "FURNITURE"]
}
]
}
  • File Name: file.json

  • JSON Path: $.products[*]

Ouput

{
"total": 4,
"success": 4,
"failed": 0
}

Each object inside the "products" array of the informed file will be processed in an independent way:

  • First subflow

{"data": {
"product": "Chair",
"price": 20.75,
"tags": ["NEW", "FURNITURE"]
}}
  • Second subflow

{"data": {
"product": "TV",
"price": 399.99,
"tags": ["NEW", "FURNITURE"]
}}
  • Third subflow

{"data": {
"product": "Couch",
"price": 100,
"tags": ["NEW", "FURNITURE"]
}}
  • Forth subflow

{"data": {
"product": "Table",
"price": 78.99,
"tags": ["NEW", "FURNITURE"]
}}

Making the file stream with filters in JSON Path

Input

  • file.json

{
"products" : [
{
"product": "Chair",
"price": 20.75,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "TV",
"price": 399.99,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "Couch",
"price": 100,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "Table",
"price": 78.99,
"tags": ["NEW", "FURNITURE"]
}
]
}
  • File Name: file.json

  • JSON Path: $.products[?(@.price < 80)]

Output

{
"total": 2,
"success": 2,
"failed": 0
}

Each object inside the "products" array of the informed file will be processed in an independent way:

  • First subflow

{"data": {
"product": "Chair",
"price": 20.75,
"tags": ["NEW", "FURNITURE"]
} }
  • Second subflow

{"data": {
"product": "Table",
"price": 78.99,
"tags": ["NEW", "FURNITURE"]
}}

Making the file stream with filters in JSON Path and returning the ‘product’ attribute value only

Input

  • file.json

{
"products" : [
{
"product": "Chair",
"price": 20.75,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "TV",
"price": 399.99,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "Couch",
"price": 100,
"tags": ["NEW", "FURNITURE"]
},
{
"product": "Table",
"price": 78.99,
"tags": ["NEW", "FURNITURE"]
}
]
}
  • File Name: file.json

  • JSON Path: $.products[?(@.price < 80)].product

Ouput

{
"total": 2,
"success": 2,
"failed": 0
}

Each object inside the "products" array of the informed file will be processed in an independent way:

  • First subflow

{"data": "Chair" }
  • Second subflow

{"data": "Table" }

Last updated