How to use 'javascript json decode' in JavaScript

Every line of 'javascript json decode' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
5function decode(json) {
6 return JSON.parse(json);
7}
39static decode(obj: any) {
40 if (obj && obj.$type === 'ObjectId') {
41 return new MongoDb.ObjectID(obj.$value);
42 }
43 if (obj && obj.$type === "Date") {
44 return new Date(obj.$value);
45 }
46 if (obj && obj.$type === "RegExp") {
47 return new RegExp(obj.$value.$pattern, obj.$value.$flags);
48 }
49 if (Array.isArray(obj)) {
50 return [...obj.map(JsonEncoder.decode)];
51 }
52 if (obj && typeof obj === 'object') {
53 for (const [key, value] of Object.entries(obj)) {
54 obj[key] = JsonEncoder.decode(value);
55 }
56 }
57
58 return obj;
59}

Related snippets