JSON and JSON Lines driver

Read JSON records and write typed JSON output with the built-in JSON driver.

Configure the connection

Use driver="json" and set url to a path relative to the ETL file. Use separate connections for input and output. The default encoding is UTF-8. Set format=json for a JSON document or format=jsonl for JSON Lines. If you omit format, .jsonl and .ndjson select JSON Lines and other filenames select document JSON.

The binary distribution includes Jackson Core. Maven applications must add that optional dependency explicitly.

Read and write records

  • JSON document. A query with no filter text reads each root array item as a row or emits a root object as one row. A simple path such as response.customers selects a nested array. Each output script emits an object into a single output array.
  • JSON Lines. Leave the query text empty. Each physical line contains one JSON value, and each output script writes one compact object followed by a newline.

Each input record is available as row. Use an unquoted ?{expression} for a complete dynamic value in an output object. Numbers, booleans, null, arrays and objects retain their types, and strings are escaped automatically. Quoted placeholders produce literal strings. Format dates explicitly before writing them.

Convert a JSON array to JSON Lines

Save this input as customers.json.

[{"id":1,"name":"Ada","active":true},{"id":2,"name":"Lin","active":false}]

Save the ETL file beside it as copy-json.etl.xml and run scriptella.sh copy-json.etl.xml.

<?xml version="1.0"?>
<!DOCTYPE etl SYSTEM "http://scriptella.org/dtd/etl.dtd">
<etl>
    <connection id="input" driver="json" url="customers.json"/>
    <connection id="output" driver="json" url="customers-out.jsonl"/>
    <query connection-id="input">
        <script connection-id="output">
            {"id": ?{row.id}, "name": ?{row.name}, "active": ?{row.active}}
        </script>
    </query>
</etl>

The new customers-out.jsonl contains one object per line.

{"id":1,"name":"Ada","active":true}
{"id":2,"name":"Lin","active":false}

Input and output limits

Document queries use simple array selection paths. JSONPath operators and filters are unsupported. JSON Lines rejects blank lines and multiline records. Output is nontransactional, so a failed run can leave a partial file. Zero output script invocations leave the destination untouched.

See the JSON driver Javadoc for path syntax, supported types and failure behavior, or follow the PostgreSQL-to-JSON guide for a database export.