Urgent.News

What's breaking now, across thousands of outlets.

Tech

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…

When a JSONL file contains a malformed record, it can be challenging to pinpoint and correct the issue. That's where JSONSEEK comes in handy. This tool, developed by the author, simplifies the process of locating the problematic line, previewing a replacement, and then checking the file again. To demonstrate its functionality, a small example is provided.

First, the JSONL file is displayed using the command `cat sample.jsonl`. In the shown example, line 2 is identified as the malformed record. Once the issue is known, JSONSEEK's `replaceline` command is used to preview the replacement before making any changes. The second command, `jsonseek replaceline sample.jsonl 2 { id :2, name : Grace } --dry-run`, previews the change.

For the actual replacement, the command `jsonseek replaceline sample.jsonl 2 { id :2, name : Grace } --backup` is used. This not only makes the change but also creates a backup with the `.bak` extension. The final step is to verify the result using the `shape` command: `jsonseek shape sample.jsonl`. This ensures that the repaired file is now valid.

In addition to its primary functionality, JSONSEEK offers other command-line interface (CLI) commands for inspecting JSON and JSONL files. These include commands for fields, listing items with `ls`, searching with `query`, and editing values with commands such as `set` and `add`. The tool is released under the MIT license and the repository provides a command reference along with more examples.

Working with JSONL files often involves finding and repairing malformed records. JSONSEEK simplifies this process by allowing users to inspect the relevant structure or record before making any changes.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Artifex Ignotvs — Relatio 000

I publish as Artifex Ignotvs . The seal carries a question mark. Before I trust a security claim, I want to know what was examined, how it was tested, and where the result stops being reliable.

More from Wednesday 14 October →