Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,757 questions

17,364 answers

573 users

How to use function in JSON.parse with JavaScript

3 Answers

0 votes
const json = '{"1": "A", "2": "B", "3": "C", "4": "D", "5": "E"}';

const parsedJson = JSON.parse(json, (key, value) => {
    if (key == 3)
        console.log('key == 3');

    if (key == 5)
		console.log('key == 5');

    return value; 
});

console.log(parsedJson);



  
/*
run:

key == 3
key == 5
{ '1': 'A', '2': 'B', '3': 'C', '4': 'D', '5': 'E' }

*/

 




answered Mar 20 by avibootz
0 votes
const json = '{"1": "A", "2": "B", "3": "C", "4": "D", "5": "E"}';
 
const parsedJson = JSON.parse(json, (key, value) => {
	console.log(key, value);
});
 
 
 
   
/*
run:
 
1 A
2 B
3 C
4 D
5 E
 {}
 
*/

 




answered Mar 20 by avibootz
0 votes
const json = '{"1": "A", "2": "B", "3": "C", "4": "D", "5": "E"}';
 
const parsedJson = JSON.parse(json, (key, value) => {
    if (key == 3)
        return 'JavaScript';
 
    if (key == 5)
		return 'Node.js';
 
    return value; 
});
 
console.log(parsedJson);
 
 
 
   
/*
run:
 
{ '1': 'A', '2': 'B', '3': 'JavaScript', '4': 'D', '5': 'Node.js' }
 
*/

 




answered Mar 20 by avibootz
edited Mar 20 by avibootz
...