neuroo / json-ast Goto Github PK
View Code? Open in Web Editor NEWThis project forked from vtrushin/json-to-ast
A tolerant JSON parser for Node
Home Page: https://www.npmjs.com/package/json-ast
License: MIT License
This project forked from vtrushin/json-to-ast
A tolerant JSON parser for Node
Home Page: https://www.npmjs.com/package/json-ast
License: MIT License
It would be great if junker will allow to read over missing comma like in this case:
{
"key1": "value1"
"key2": 1
}
Repro steps:
git clone https://github.com/neuroo/json-ast/issues/new
Expected:
Pass
Actual:
..............................
29 passing (78ms)
1 failing
1) Test cases multi-line-comments-in-object:
AssertionError [ERR_ASSERTION]: asts are not equal
+ expected - actual
const ast = require("json-ast")
const {parse, Visitor, AST} = ast;
const json = `
{
"type": "regex",
"pattern": "^\\w+$",
"errorMsg": "Characters of Name should match regex ^\\w+$ ."
}
`
parse(json)
I discovered while traversing a produced AST that the node positions extended beyond the length of the file, nearly doubling the line length. After poking around and testing a hypothesis, I discovered that by normalizing lines endings to "\n", the line count returned to normal.
Operating System: Windows (works as expected on Mac)
Line ending: Windows standard (\r\n)
JSON source in question:
{
"Snippet snippet": {
"prefix": "snippet",
"body": [
"\"$1\": {",
"\t\"prefix\": \"$2\",",
"\t\"body\": [",
"\t\t$3",
"\t],",
"\t\"description\": \"$4\"",
"},"
],
"description": "A snippet for creating new snippets"
}
}
The normalization fix I applied in my parser abstraction is as follows:
function normalizeSourceLineEndings(source) {
return source.split(/\r?\n/).join('\n');
}
I know this project is old, and potentially unmaintained, but I figured this issue would, at least, help someone else if they encountered a similar issue.
Thank you for building this.
Cheers!
I would like to use this package to pars and then pretty print JSON with comments. How can I do that? Using AST.JsonDocument.toJSON(ast)
and similar methods does not sustain comments
The junker should handle this contents fine:
{
name: "there",
version: 2.0
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.