JSONL Recipes for Developers

JSONL is easiest to work with when you treat each non-empty line as one complete JSON value. These small recipes cover the jobs developers repeat most often.

Read line by line

import json

with open("data.jsonl", encoding="utf-8") as file:
    for line_number, line in enumerate(file, 1):
        if line.strip():
            record = json.loads(line)
            print(line_number, record)

Filter with jq

jq -c 'select(.status == "active")' input.jsonl > active.jsonl

Stream in JavaScript

const records = input.split(/\r?\n/).filter(Boolean).map(JSON.parse);
for (const record of records) console.log(record);

Choose the next tool