Back to Practice
#0146

Parse Valid JSONL Records

MediumPython25 min20 XP

Problem

Given a string containing JSON objects separated by newlines, return the parsed dictionaries for valid lines only.

Why This Matters

Real data logs often contain one malformed line. Good scripts report or skip the bad record instead of crashing the full job.

Function Signature

def parse_jsonl(text):

Examples

Example 1
Input'{"id": 1}\nnot-json\n{"id": 2}'
Output[{'id': 1}, {'id': 2}]

The invalid middle line is ignored, while valid JSON objects are returned.

Constraints

  • Return the exact requested value.
  • Handle empty or small inputs when the prompt allows them.
  • Keep the code readable and deterministic.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input'{"id": 1}\nnot-json\n{"id": 2}'
Expected[{'id': 1}, {'id': 2}]

The invalid middle line is ignored, while valid JSON objects are returned.

Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input