SlideShare a Scribd company logo
Json.parse() in JavaScript
JSON.parse() takes a JSON string and transforms it
into a JavaScript object.
Syntax:
JSON.parse( stringValue, [reviver] );
- stringValue JSON-string to parse
- reviver function(key, value), function to
transform the value
const json = ‘{"string":"Hello
Nugget!","number":123456,
"boolean":false,"test":null}’;
let obj = JSON.parse(json);
console.log(obj);
console.log(obj.string);
//Output
{
string: “Hello Nugget!”,
number: 123456,
boolean: false,
null: null
}
Hello Nugget!
// Output
{
string: “Hello Nugget!”,
number: 123456,
boolean: “setting true”,
null: null
}
true
JSON.parse(jsonString, function(key, value) {
// some operation
// return value for the key
return value;
});
Using reviver function:
This function is to modify the result before
returning.
let obj = JSON.parse(json,
(key, value) => {
return key === ‘boolean’ ?
‘setting true’: true
});
console.log(obj);
console.log(obj.boolean);

More Related Content

What's hot (20)

PPTX
An Introduction to WebWorker - 01.26.12
Digiflare
 
PDF
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
 
PDF
Better react/redux apps using redux-saga
Younes (omar) Meliani
 
PPTX
Javascript this keyword
Pham Huy Tung
 
PDF
JavaScript, TypeScipt and React Native
Mitchell Tilbrook
 
DOCX
Ejercicios
leonharo
 
PDF
Callbacks and control flow in Node js
Thomas Roch
 
PDF
Kotlin wonderland
Jedsada Tiwongvokul
 
PDF
JavaScript promise
eslam_me
 
PDF
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
PPTX
Aspdevice - Asp Fast Crud introdution
Adriano Mendes
 
PDF
Async History - javascript
Nishchit Dhanani
 
PPTX
Boot strap.groovy
Vijay Shukla
 
KEY
Engineering JavaScript
Jim Purbrick
 
PDF
JavaSE7 Launch Event: Java7xGroovy
Yasuharu Nakano
 
PDF
Minion pool - a worker pool for nodejs
Marcelo Gornstein
 
PPTX
JS Objects manipulation
City University of Macau
 
PPT
Χρήση Vba για την πρόσβαση σε βάση δεδομένων
Nikos Mpalatsoukas
 
PDF
New feature of async fakeAsync test in angular
Jia Li
 
PPTX
Javascript Execution Context Flow
kang taehun
 
An Introduction to WebWorker - 01.26.12
Digiflare
 
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
 
Better react/redux apps using redux-saga
Younes (omar) Meliani
 
Javascript this keyword
Pham Huy Tung
 
JavaScript, TypeScipt and React Native
Mitchell Tilbrook
 
Ejercicios
leonharo
 
Callbacks and control flow in Node js
Thomas Roch
 
Kotlin wonderland
Jedsada Tiwongvokul
 
JavaScript promise
eslam_me
 
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
Aspdevice - Asp Fast Crud introdution
Adriano Mendes
 
Async History - javascript
Nishchit Dhanani
 
Boot strap.groovy
Vijay Shukla
 
Engineering JavaScript
Jim Purbrick
 
JavaSE7 Launch Event: Java7xGroovy
Yasuharu Nakano
 
Minion pool - a worker pool for nodejs
Marcelo Gornstein
 
JS Objects manipulation
City University of Macau
 
Χρήση Vba για την πρόσβαση σε βάση δεδομένων
Nikos Mpalatsoukas
 
New feature of async fakeAsync test in angular
Jia Li
 
Javascript Execution Context Flow
kang taehun
 

Similar to Json.parse() in JavaScript (14)

PPTX
JSON-(JavaScript Object Notation)
Skillwise Group
 
PPTX
module 2.pptx for full stack mobile development application on backend applic...
HemaSenthil5
 
PPT
J s-o-n-120219575328402-3
Ramamohan Chokkam
 
PDF
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
PPTX
Working with JSON
Lovely Professional University
 
PPTX
Working with JSON.pptx
Lovely Professional University
 
PDF
JSON in JavaScript
Bishrul Haq
 
PDF
Unit-2 JSON.pdf
hskznx
 
PPT
java script json
chauhankapil
 
PDF
CS8651 IP Unit 2 pdf regulation -2017 anna university
amrashbhanuabdul
 
PDF
Json tutorial for beginners phptpoint
phptpoint
 
DOC
quick json parser
Rajesh Putta
 
PPTX
Json training
Elavarasi Dc
 
PPTX
Unit-2.pptx
AnujSood25
 
JSON-(JavaScript Object Notation)
Skillwise Group
 
module 2.pptx for full stack mobile development application on backend applic...
HemaSenthil5
 
J s-o-n-120219575328402-3
Ramamohan Chokkam
 
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
Working with JSON.pptx
Lovely Professional University
 
JSON in JavaScript
Bishrul Haq
 
Unit-2 JSON.pdf
hskznx
 
java script json
chauhankapil
 
CS8651 IP Unit 2 pdf regulation -2017 anna university
amrashbhanuabdul
 
Json tutorial for beginners phptpoint
phptpoint
 
quick json parser
Rajesh Putta
 
Json training
Elavarasi Dc
 
Unit-2.pptx
AnujSood25
 
Ad

More from Ideas2IT Technologies (20)

PDF
Version comaparison in JavaScript
Ideas2IT Technologies
 
PDF
Currying in JavaScript
Ideas2IT Technologies
 
PDF
JS Testing Frameworks
Ideas2IT Technologies
 
PDF
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
PDF
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
PDF
String comparison in javascript
Ideas2IT Technologies
 
PDF
JavaScript symbols
Ideas2IT Technologies
 
PDF
Bubble sort in Java Script
Ideas2IT Technologies
 
PDF
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
PDF
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
PDF
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
PDF
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
PDF
Variable hoisting in JavaScript
Ideas2IT Technologies
 
PDF
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-2
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-1
Ideas2IT Technologies
 
PDF
Array vs set in JavaScript
Ideas2IT Technologies
 
Version comaparison in JavaScript
Ideas2IT Technologies
 
Currying in JavaScript
Ideas2IT Technologies
 
JS Testing Frameworks
Ideas2IT Technologies
 
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
String comparison in javascript
Ideas2IT Technologies
 
JavaScript symbols
Ideas2IT Technologies
 
Bubble sort in Java Script
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Variable hoisting in JavaScript
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
Logging in JavaScript - part-2
Ideas2IT Technologies
 
Logging in JavaScript - part-1
Ideas2IT Technologies
 
Array vs set in JavaScript
Ideas2IT Technologies
 
Ad

Recently uploaded (20)

PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 

Json.parse() in JavaScript

  • 2. JSON.parse() takes a JSON string and transforms it into a JavaScript object. Syntax: JSON.parse( stringValue, [reviver] ); - stringValue JSON-string to parse - reviver function(key, value), function to transform the value const json = ‘{"string":"Hello Nugget!","number":123456, "boolean":false,"test":null}’; let obj = JSON.parse(json); console.log(obj); console.log(obj.string); //Output { string: “Hello Nugget!”, number: 123456, boolean: false, null: null } Hello Nugget!
  • 3. // Output { string: “Hello Nugget!”, number: 123456, boolean: “setting true”, null: null } true JSON.parse(jsonString, function(key, value) { // some operation // return value for the key return value; }); Using reviver function: This function is to modify the result before returning. let obj = JSON.parse(json, (key, value) => { return key === ‘boolean’ ? ‘setting true’: true }); console.log(obj); console.log(obj.boolean);