Writes each received array as a JSON document on its own line (JSON Lines format), in a file whose path is set in the options. As a blocking task, it waits until all inputs have been received and then outputs the file path.
- Service:
CleverAge\ProcessBundle\Task\File\JsonStream\JsonStreamWriterTask - Blocking task
array: data to encode. An \UnexpectedValueException is thrown for any other type.
Underlying method is json_encode.
string: path of the written file (with placeholders replaced), once all inputs have been processed.
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
file_path |
string |
X | Path of the file to write to, opened in wb mode (overwritten).Placeholders {date}, {date_time}, {timestamp} and {unique_token} are replaced in the path |
|
spl_file_object_flags |
array|null |
null |
List of SplFileObject flags, summed and passed to SplFileObject::setFlags.null means DROP_NEW_LINE, READ_AHEAD and SKIP_EMPTY; an empty array means no flag |
|
json_flags |
array|null |
null |
List of JSON flags, summed and passed to json_encode.null means JSON_THROW_ON_ERROR; an empty array means no flag |
# Task configuration level
entry:
service: '@CleverAge\ProcessBundle\Task\ConstantIterableOutputTask'
options:
output:
- column1: value1-1
column2: value2-1
- column1: value1-2
column2: value2-2
outputs: [write]
write:
service: '@CleverAge\ProcessBundle\Task\File\JsonStream\JsonStreamWriterTask'
options:
file_path: '%kernel.project_dir%/var/data/json_stream_writer_{date_time}.json'
json_flags:
- !php/const JSON_THROW_ON_ERROR
- !php/const JSON_UNESCAPED_SLASHES
- !php/const JSON_UNESCAPED_UNICODE{date}is replaced byYmd,{date_time}byYmd_His,{timestamp}by the Unix timestamp and{unique_token}by auniqid()value.- The parent directory of the file must exist.
- Using
JSON_PRETTY_PRINTproduces multi-line documents: the file can no longer be read by JsonStreamReaderTask.