|
1 | | -<!doctype html> |
2 | | -<html lang="en"> |
3 | | -<head> |
4 | | - <meta charset="utf-8" /> |
5 | | - <title>JSON Lint</title> |
6 | | - <script src="json2.js"></script> |
7 | | - <script src="jsonlint.js"></script> |
8 | | - <script> |
9 | | - window.onload = function () { |
10 | | - document.getElementById("button").onclick = function () { |
11 | | - try { |
12 | | - var parser = jsonlint |
13 | | - if (document.getElementById("comments").checked) { |
14 | | - parser = new jsonlint.parser.ParserWithComments |
15 | | - } |
16 | | - var result = parser.parse(document.getElementById("source").value); |
17 | | - if (result) { |
18 | | - document.getElementById("result").innerHTML = "JSON is valid!"; |
19 | | - document.getElementById("result").className = "pass"; |
20 | | - if (document.getElementById("reformat").checked) { |
21 | | - document.getElementById("source").value = JSON.stringify(result, null, " "); |
22 | | - } |
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | + <meta name="description" content="JSON validator - checks syntax of a JSON source."> |
| 7 | + <title>JSON Lint</title> |
| 8 | + <style> |
| 9 | + body { |
| 10 | + font-family: sans-serif; |
| 11 | + margin: 1ex; |
| 12 | + } |
| 13 | + #source, #result { |
| 14 | + padding: 1ex; |
| 15 | + } |
| 16 | + #source, #validate { |
| 17 | + font-size: 100%; |
| 18 | + } |
| 19 | + #source { |
| 20 | + font-family: monospace; |
| 21 | + width: calc(100% - 2ex); |
| 22 | + } |
| 23 | + #result-section { |
| 24 | + display: none; |
| 25 | + } |
| 26 | + .pass { |
| 27 | + background-color: #efe; |
| 28 | + color: #393; |
| 29 | + border: 2px solid #393; |
| 30 | + } |
| 31 | + .fail { |
| 32 | + background-color: #fee; |
| 33 | + color: #933; |
| 34 | + border: 2px solid #933; |
| 35 | + } |
| 36 | + </style> |
| 37 | +</head> |
| 38 | + |
| 39 | +<body> |
| 40 | + <header> |
| 41 | + <h1>JSON Lint</h1> |
| 42 | + <p>Enter a JSON source and check its syntax in the form below. A pure JavaScript version of the service provided at <a href="http://jsonlint.com/">jsonlint.com</a>.</p> |
| 43 | + </header> |
| 44 | + <main> |
| 45 | + <section> |
| 46 | + <form> |
| 47 | + <h2>Source</h2> |
| 48 | + <textarea id="source" rows="10" cols="50" aria-label="Source"></textarea> |
| 49 | + <p> |
| 50 | + <input type="checkbox" checked id="reformat"> |
| 51 | + <label for="reformat">Reformat source</label> |
| 52 | + <span> </span> |
| 53 | + <input type="checkbox" id="comments"> |
| 54 | + <label for="comments">Ignore JavaScript-style comments</label> |
| 55 | + </p> |
| 56 | + <p> |
| 57 | + <button id="validate" type="button">Validate</button> |
| 58 | + </p> |
| 59 | + </form> |
| 60 | + </section> |
| 61 | + <section id="result-section"> |
| 62 | + <h2>Result</h2> |
| 63 | + <pre id="result"></pre> |
| 64 | + </section> |
| 65 | + </main> |
| 66 | + <hr> |
| 67 | + <footer> |
| 68 | + <small>Copyright © 2012-2019 Zachary Carter, Ferdinand Prantl. Licensed under the MIT license. View the <a href="https://github.com/prantlf/jsonlint#json-lint">project on GitHub</a>.</small> |
| 69 | + <!-- See http://tholman.com/github-corners/ --> |
| 70 | + <a href="http://github.com/prantlf/jsonlint" class="github-corner" title="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style> |
| 71 | + </footer> |
| 72 | + <script src="jsonlint.js" defer></script> |
| 73 | + <script defer> |
| 74 | + window.onload = function () { |
| 75 | + document.getElementById('validate').onclick = function () { |
| 76 | + document.getElementById('result-section').style.display = 'block' |
| 77 | + try { |
| 78 | + var parser = jsonlint.parser |
| 79 | + if (document.getElementById('comments').checked) { |
| 80 | + parser = new parser.ParserWithComments() |
| 81 | + } |
| 82 | + var result = parser.parse(document.getElementById('source').value) |
| 83 | + if (result) { |
| 84 | + document.getElementById('result').innerText = 'JSON is valid!' |
| 85 | + document.getElementById('result').className = 'pass' |
| 86 | + if (document.getElementById('reformat').checked) { |
| 87 | + document.getElementById('source').value = JSON.stringify(result, null, ' ') |
23 | 88 | } |
24 | | - } catch(e) { |
25 | | - document.getElementById("result").innerHTML = e; |
26 | | - document.getElementById("result").className = "fail"; |
27 | 89 | } |
28 | | - }; |
29 | | - } |
30 | | - </script> |
31 | | - <style> |
32 | | - body {font-family: sans-serif;} |
33 | | - #result { |
34 | | - padding: 1em; |
35 | | - } |
36 | | - .pass { |
37 | | - background-color: #efe; |
38 | | - color: #393; |
39 | | - border: 2px solid #393; |
40 | | - } |
41 | | - .fail { |
42 | | - background-color: #fee; |
43 | | - color: #933; |
44 | | - border: 2px solid #933; |
| 90 | + } catch (error) { |
| 91 | + document.getElementById('result').innerText = error |
| 92 | + document.getElementById('result').className = 'fail' |
| 93 | + } |
45 | 94 | } |
46 | | - textarea { width: 100%; } |
47 | | - </style> |
48 | | -</head> |
49 | | -<body> |
50 | | - <h1>JSON Lint</h1> |
51 | | - <p>A pure JavaScript version of the service provided at <a href="http://jsonlint.com/">jsonlint.com</a>.</p> |
52 | | - <textarea id="source" rows="20" cols="50"></textarea> |
53 | | - <p> |
54 | | - <input type="checkbox" checked id="reformat"> |
55 | | - <label for="reformat">reformat JSON</label> |
56 | | - <br> |
57 | | - <input type="checkbox" id="comments"> |
58 | | - <label for="comments">ignore JavaScript-style comments</label> |
59 | | - </p> |
60 | | - <p> |
61 | | - <button id="button">Validate</button> |
62 | | - </p> |
63 | | - <h2>Results</h2> |
64 | | - <pre id="result"></pre> |
65 | | - <p><a href="http://github.com/prantlf/jsonlint">project on github</a></p> |
66 | | -</body> |
67 | | -</html> |
| 95 | + } |
| 96 | + </script> |
| 97 | +</body> |
| 98 | +</html> |
0 commit comments