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)

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

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

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

More from Ideas2IT Technologies (20)

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

Recently uploaded (20)

Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 

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);