Closed hkasera closed 1 year ago
How about a 1 liner?
python -c 'import sys;import json;[None for line in sys.stdin if json.loads(line)]'
Would be better if it could display the line number and offending line, but exit 0 means it contains no errors.
I think we could have one in javascript, so we could easily put it into a webpage. Writing it down here, but this would be something like:
let lines = jsonl.split('\n');
let errors = '';
for (let i = 0; i < lines.length; i++) {
let line = lines[i]
if (i !== lines.length -1 && lines !== '') {
try {
JSON.parse(line);
} catch(e) {
if (e instanceof SyntaxError) {
errors += `line ${i}: error ${e}\n`;
} else {
throw e;
}
}
}
}
if (errors !== '') {
console.log(errors)
} else {
console.log('valid jsonl');
}
Hi, I opened a pull request for the web validator on the website, please have a look
CC @wardi
A validator to validate .jsonl files or the content just like jsonlint