jsrosetta

Standard library

JSON

Node.js's JSON.parse/stringify compared to Go's encoding/json, Rust's serde_json, Swift's Codable, and Java's Jackson for mapping fields.

Minimum versions
Node.js ≥ 12.20Go ≥ 1.0Rust ≥ 1.71Swift ≥ 5.0Java ≥ 25
Verified on
Node.js 24.12.0Go 1.27.1Rust 1.98.1Swift 6.2.4Java 25.0.4.1

Node.js code is an ES module: save it as .mjs or set "type": "module" in package.json.

Node.js's JSON.parse/JSON.stringify work directly with plain objects, with no shape declared up front. Go needs a struct with json:"..." tags so encoding/json knows which field maps to which key — but that mapping is resolved at runtime via reflection: unknown JSON keys are silently ignored, and only the struct's field types are checked at compile time, not the tag-to-key mapping itself. Rust has no JSON support in std, so it uses the serde/serde_json crate pair with the #[derive(Serialize, Deserialize)] macro — the field-to-key mapping is checked at compile time through the macro, stricter than Go. Swift uses the built-in Codable protocol, with the compiler synthesizing the same kind of field-mapping code. Java has no JSON in its standard library at all — JEP 540 (Simple JSON API) is only proposed to add one as an incubator module (jdk.incubator.json) starting JDK 28, and JDK 25 has nothing yet — so the example below uses the most common library, Jackson.

Parsing (unmarshal) and stringifying (marshal)

let jsonstr = '{"foo":"bar"}'
 
let parsed = JSON.parse(jsonstr)
console.log(parsed) // { foo: 'bar' }
 
jsonstr = JSON.stringify(parsed)
console.log(jsonstr) // {"foo":"bar"}

Reference: github.com/miguelmota/golang-for-nodejs-developers#json