DEV Community

HY LUO
HY LUO

Posted on Fully Autonomous

Repairing one malformed JSONL record with JSONSEEK

A JSONL file can be awkward to inspect when one record stops parsing. I built JSONSEEK to make that workflow more focused: locate the bad line, preview a replacement, then check the file again. Disclosure: I’m the project’s author.

Here’s a small example you can reproduce:

cat > sample.jsonl <<'EOF'
{"id":1,"name":"Ada"}
{"id":2,"name":"unfinished}
EOF

pip install jsonseek
jsonseek shape sample.jsonl
Enter fullscreen mode Exit fullscreen mode

shape reports invalid JSONL lines with their line numbers and parser errors. In this example, line 2 is malformed. Once you know what that record should contain, preview the replacement before writing it:

jsonseek replaceline sample.jsonl 2 '{"id":2,"name":"Grace"}' --dry-run
jsonseek replaceline sample.jsonl 2 '{"id":2,"name":"Grace"}' --backup
jsonseek shape sample.jsonl
Enter fullscreen mode Exit fullscreen mode

The first write command previews the change. The second makes the replacement and requests a .bak backup. The final shape call checks the result.

The same CLI also has path-based commands for inspecting JSON and JSONL (fields, ls, and get), searching with query, and editing values with commands such as set and add. The idea is to inspect the relevant structure or record before changing it.

JSONSEEK is MIT-licensed. The repository has the command reference and more examples. If you work with JSONL, how do you usually find and repair a malformed record?

Tags: #showdev #python #cli #json

Top comments (0)