{"id":18459,"library":"json-to-ast","title":"json-to-ast","description":"A lightweight, zero-dependency JSON parser that produces an Abstract Syntax Tree (AST) with full location information. Version 2.1.0 supports Emoji, runs on Node >=4, and provides error messages with precise character offsets. Unlike JSON.parse, it returns a structured tree with node types like 'object', 'array', 'identifier', 'literal' and detailed 'loc' (location) data including line, column, offset, and source. Ideal for linters, formatters, code mods, and tools needing to analyze or manipulate JSON structure. Last released in 2019 with no recent updates, possibly in maintenance mode.","status":"maintenance","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/vtrushin/json-to-ast","tags":["javascript","json-parser","parser","ast","json","tree"],"install":[{"cmd":"npm install json-to-ast","lang":"bash","label":"npm"},{"cmd":"yarn add json-to-ast","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-to-ast","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v2? Actually CJS is still supported but default export is used; both works, but ensure you handle default import correctly.","wrong":"const parse = require('json-to-ast')","symbol":"default","correct":"import parse from 'json-to-ast'"},{"note":"Named export 'parse' also available; both default and named export point to same function.","wrong":"const { parse } = require('json-to-ast')","symbol":"parse","correct":"import { parse } from 'json-to-ast'"},{"note":"Type imports require 'import type' in TypeScript if using as types only.","wrong":"import { ASTNode } from 'json-to-ast'","symbol":"type imports","correct":"import type { ASTNode, ValueNode } from 'json-to-ast'"}],"quickstart":{"code":"import parse from 'json-to-ast';\n\nconst json = '{ \"name\": \"Alice\", \"age\": 30 }';\nconst ast = parse(json, { loc: true, source: 'example.json' });\n\nconsole.log(JSON.stringify(ast, null, 2));\n// Output: \n// {\n//   \"type\": \"object\",\n//   \"children\": [\n//     {\n//       \"type\": \"property\",\n//       \"key\": { \"type\": \"identifier\", \"value\": \"name\", ... },\n//       \"value\": { \"type\": \"literal\", \"value\": \"Alice\", ... }\n//     },\n//     {\n//       \"type\": \"property\",\n//       \"key\": { \"type\": \"identifier\", \"value\": \"age\", ... },\n//       \"value\": { \"type\": \"literal\", \"value\": 30, ... }\n//     }\n//   ],\n//   \"loc\": { ... }\n// }","lang":"typescript","description":"Parses a JSON string into an AST with location info (loc: true) and source name."},"warnings":[{"fix":"Use 'loc: true' instead of 'verbose: true'; update node type references to new names.","message":"v2.0.0 renamed 'verbose' option to 'loc' and changed node type names (e.g., 'value' to 'literal', 'key' to 'identifier').","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Access 'raw' instead of 'rawValue' on literal nodes.","message":"v2.0.0 changed 'rawValue' to 'raw' in literal nodes.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Access 'loc' instead of 'position' for location data.","message":"v2.0.0 changed 'position' property to 'loc'.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Consider alternatives like @humanwhocodes/momoa or moo/ace for active development.","message":"The package has not been updated since 2019. No future updates expected.","severity":"deprecated","affected_versions":">=2.1.0"},{"fix":"Use named import for clarity: import { parse } from 'json-to-ast';","message":"Default export and named export 'parse' both exist, but some bundlers may treat default export differently.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure 'source' is a string: parse(json, { source: 'file.json' })","cause":"Passing a non-string value (e.g., number or object) for the 'source' option.","error":"Error: The 'source' option must be a string"},{"fix":"Use correct import: import parse from 'json-to-ast' or const parse = require('json-to-ast').default (for CJS with named export).","cause":"Importing the module incorrectly in CJS or ESM environment.","error":"TypeError: parse is not a function"},{"fix":"Check the JSON input validity; the error message includes location details (line, column, offset).","cause":"The input string is not valid JSON or has extra characters. json-to-ast throws a custom error with line/column info.","error":"SyntaxError: Unexpected token in JSON at position X"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}