PageSourceSearch

https://jsonlines.org/javascripts/validator.js

js jsonlines.org collected 2026-09-24 07:21:37 UTC 1,148 bytes, 46 lines download raw bytes

1/* VALIDATOR */
2
3$(document).ready(() => {
4  // CodeMirror editor
5  let editor = CodeMirror.fromTextArea(jQuery('.validator textarea')[0], {
6    lineNumbers: true,
7    theme: 'abbott',
8    mode: 'javascript',
9  });
10  
11  // clear button
12  jQuery('.validator input[type="button"][value="clear"]').click(() => {
13    editor.setValue('');
14  });
15
16  // validate button
17  jQuery('.validator input[type="button"][value="validate"]').click(() => {
18    let jsonl = editor.getValue();
19    let lines = jsonl.split('\n');
20    let errors = [];
21    for (let i = 0; i < lines.length; i++) {
22      let line = lines[i]
23      if (i !== lines.length - 1 || lines[i] !== '') {
24        try {
25          JSON.parse(line);
26        } catch (e) {
27          if (e instanceof SyntaxError) {
28            errors.push(`line ${i + 1}: error ${e}\n`);
29          } else {
30            throw e;
31          }
32        }
33      }
34    }
35
36    let result = jQuery('.validator div.result ul');
37    result.empty();
38    if (0 < errors.length) {
39      errors.forEach((error) => {
40        result.append(`<li>${error}</li>`);
41      });
42    } else {
43      result.append('valid jsonl')
44    }
45  });
46});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.