Skip to content

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vanilla-JSON

Zero-dependency JSON library built from scratch — a hand-written tokenizer, a recursive descent parser, and a serializer. No shortcuts, no eval, no native JSON.* calls anywhere in the implementation.

Install

npm i @rabia_youcef/vanilla-json

Usage

const VJSON = require("@rabia_youcef/vanilla-json")

VJSON.parse('{"name":"salamo","tags":[1,true,null]}')
// → { name: "salamo", tags: [1, true, null] }

VJSON.stringify({ a: 1, b: [true, "text"] })
// → '{"a":1,"b":[true,"text"]}'

Behavior

Matches native JSON.parse / JSON.stringify, including the weird parts:

Case Result
stringify(NaN), stringify(Infinity) "null"
undefined / functions in arrays become null
undefined / functions as object values key is dropped
Circular references throws TypeError, like native
String escaping \" \\ \n \t \r
Trailing commas, missing colons, unquoted keys throw SyntaxError with position info

How it works

parse runs a two-phase pipeline: a tokenizer converts raw text into typed tokens, then a recursive descent parser (parseValue / parseArray / parseObject) consumes them and builds live values. stringify walks values recursively, tracking the current path in a WeakSet to detect cycles.

Tests

npm test

License

MIT

About

A from-scratch JSON engine for JS: recursive descent parser, escape-aware tokenizer, and spec-compliant serializer. No dependencies, no shortcuts, 107 tests.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages