Installations
npm install @netocny/json-asty
Developer Guide
Typescript
No
Module System
CommonJS, UMD
Node Version
14.18.1
NPM Version
6.14.15
Score
51.2
Supply Chain
91.5
Quality
71.7
Maintenance
50
Vulnerability
98.9
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (74.89%)
PEG.js (18.98%)
Makefile (6.13%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
408
Last Day
1
Last Week
3
Last Month
14
Last Year
109
GitHub Statistics
38 Stars
83 Commits
3 Forks
4 Watchers
1 Branches
1 Contributors
Updated on Feb 01, 2025
Bundle Size
35.33 kB
Minified
12.48 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.7
Package Id
@netocny/json-asty@1.0.7
Unpacked Size
105.14 kB
Size
32.92 kB
File Count
17
NPM Version
6.14.15
Node Version
14.18.1
Total Downloads
Cumulative downloads
Total Downloads
408
Last Day
0%
1
Compared to previous day
Last Week
200%
3
Compared to previous week
Last Month
27.3%
14
Compared to previous month
Last Year
-18%
109
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Dev Dependencies
24
JSON-ASTy
Lossless JSON-to-AST Parser and AST-to-JSON Generator
About
JSON-ASTy is a JavaScript library providing a lossless JavaScript Object Notation (JSON) to Abstract Syntax Tree (AST) parser and a corresponding AST to JSON generator. It is intended for cases where one has to read JSON into an AST, manipulate the AST and generate JSON from the AST again while fully preserving the formatting of the original JSON. The AST is based on ASTy-ASTq, and hence can powerfully queried with ASTq, and manipulated with ASTy.
Installation
1$ npm install json-asty
Usage
1const JsonAsty = require("json-asty") 2 3/* the JSON input */ 4let json = `{ 5 "foo": { 6 "bar": true, 7 "baz": 42.0, 8 "quux": [ "test1\\"test2", "test3", 7, true ] 9 } 10}` 11console.log(`JSON (old):\n${json}`) 12 13/* parse JSON into AST */ 14let ast = JsonAsty.parse(json) 15console.log(`AST Dump (all):\n${JsonAsty.dump(ast, { colors: true })}`) 16 17/* the AST query */ 18let query = ` 19 .// member [ 20 ..// member [ 21 / string [ pos() == 1 && @value == "foo" ] 22 ] 23 && 24 / string [ pos() == 1 && @value == "baz" ] 25 ] 26 / * [ pos() == 2 ] 27` 28console.log(`AST Query:\n${query}`) 29 30/* query AST node */ 31let nodes = ast.query(query) 32let node = nodes[0] 33console.log(`AST Dump (sub, old):\n${node.dump()}`) 34 35/* manipulate AST node */ 36let nodeNew = node.create("string").set({ value: "TEST" }) 37node.parent().del(node).add(nodeNew) 38console.log(`AST Dump (sub, new):\n${node.dump()}`) 39 40/* unparse AST into JSON */ 41let jsonNew = JsonAsty.unparse(ast) 42console.log(`JSON (new):\n${jsonNew}`)
Output:
JSON (old):
{
"foo": {
"bar": true,
"baz": 42.0,
"quux": [ "test1\"test2", "test3", 7, true ]
}
}
AST Dump (all):
object (prolog: "{\n ", epilog: "}") [1,1]
└── member [2,5]
├── string (body: "\"foo\"", value: "foo", epilog: ": ") [2,5]
└── object (prolog: "{\n ", epilog: "}\n") [2,12]
├── member (epilog: ",\n ") [3,9]
│ ├── string (body: "\"bar\"", value: "bar", epilog: ": ") [3,9]
│ └── boolean (body: "true", value: true) [3,16]
├── member (epilog: ",\n ") [4,9]
│ ├── string (body: "\"baz\"", value: "baz", epilog: ": ") [4,9]
│ └── number (body: "42.0", value: 42) [4,16]
└── member [5,9]
├── string (body: "\"quux\"", value: "quux", epilog: ": ") [5,9]
└── array (prolog: "[ ", epilog: " ]\n ") [5,17]
├── string (body: "\"test1\\\"test2\"", value: "test1\"test2", epilog: ", ") [5,19]
├── string (body: "\"test3\"", value: "test3", epilog: ", ") [5,35]
├── number (body: "7", value: 7, epilog: ", ") [5,44]
└── boolean (body: "true", value: true) [5,47]
AST Query:
.// member [
..// member [
/ string [ pos() == 1 && @value == "foo" ]
]
&&
/ string [ pos() == 1 && @value == "baz" ]
]
/ * [ pos() == 2 ]
AST Dump (sub, old):
number (body: "42.0", value: 42) [4,16]
AST Dump (sub, new):
number (body: "42.0", value: 42) [4,16]
JSON (new):
{
"foo": {
"bar": true,
"baz": "TEST",
"quux": [ "test1\"test2", "test3", 7, true ]
}
}
License
Copyright (c) 2018-2021 Dr. Ralf S. Engelschall (http://engelschall.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More