Class JsonlParser

All Implemented Interfaces:
JsonMetaProvider, ArrayRecordReadable, RecordReadable, TokenReadable

public class JsonlParser extends JsonParser
Parses JSONL (JSON Lines) input into POJO models.
Media types

Handles Content-Type types: application/jsonl, application/jsonlines, application/x-ndjson, text/jsonl

Description

Parses JSONL input where each non-empty line is a complete JSON value. Blank lines are ignored. The conversion is as follows...

  • JSON objects ({...}) are converted to JsonMaps or Java beans if a target type is provided.
  • JSON arrays ([...]) are converted to JsonLists.
  • JSON strings are converted to Strings.
  • JSON numbers are converted to Integers, Longs, Floats, or Doubles.
  • JSON booleans are converted to Booleans.
  • JSON nulls are converted to null.

When the target type is a Collection or array, each line is parsed as one element. When the target type is a single value, only the first non-empty line is parsed.

Example:

// Use the default parser to parse JSONL into a list of POJOs List<MyBean> list = JsonlParser.DEFAULT.read(jsonlInput, List.class, MyBean.class); // Create a custom parser JsonlParser parser = JsonlParser.create().build(); // Clone an existing parser parser = JsonlParser.DEFAULT.copy().build();

Example input:

{"name":"Alice","age":30} {"name":"Bob","age":25} {"name":"Carol","age":35}

Limitations compared to JSON

  • No multi-line JSON input: Each JSON value must be on a single line. Multi-line (pretty-printed) JSON piped as JSONL input will cause parse errors.
  • First-line-only for non-collection targets: When parsing JSONL to a single non-collection type, only the first non-empty line is parsed; trailing lines are silently ignored.
Notes:
  • This class is thread safe and reusable.
See Also: