Snippets… JSON

https://www.apps4developers.com/json/

JSON String to JSON Object

const jsonString = `{“name”:”Apps4Developers.com”,”url”:”https://apps4developers.com”,”description”:”A collection of web development tutorials and examples”,”author”:{“name…


This content originally appeared on DEV Community and was authored by DEV Community

https://www.apps4developers.com/json/

JSON String to JSON Object

const jsonString = `{"name":"Apps4Developers.com","url":"https://apps4developers.com","description":"A collection of web development tutorials and examples","author":{"name":"Apps4Developers.com","url":"https://apps4developers.com"}}`;
const jsonObj = JSON.parse(jsonString);

console.log(jsonObj);

JSON Object to JSON String

const jsonObj = {
    "name": "Apps4Developers.com",
    "url": "https://apps4developers.com",
    "description": "A collection of web development tutorials and examples",
    "author": {
        "name": "Apps4Developers.com",
        "url": "https://apps4developers.com"
    }
};
const jsonString = JSON.stringify(jsonObj, null, 2);

console.log(jsonString);

JSON Object to Base64 String

const jsonObj = {
    "name": "Apps4Developers.com",
    "url": "https://apps4developers.com",
    "description": "A collection of web development tutorials and examples",
    "author": {
        "name": "Apps4Developers.com",
        "url": "https://apps4developers.com"
    }
};
const jsonString = JSON.stringify(jsonObj);
const base64String = btoa(jsonString);

console.log(base64String);

JSON Object to URL Parameter String

const jsonObj = {
    "name": "Apps4Developers.com",
    "url": "https://apps4developers.com"
};
const urlParams = new URLSearchParams(jsonObj).toString()

console.log(urlParams);

JSON Object to YAML using yaml

Install yaml package from NPM, learn more about this package here.

npm install yaml
import YAML from 'yaml';

const jsonObj = {
    "name": "Apps4Developers.com",
    "url": "https://apps4developers.com",
    "description": "A collection of web development tutorials and examples",
    "author": {
        "name": "Apps4Developers.com",
        "url": "https://apps4developers.com"
    }
};

const doc = new YAML.Document();
doc.contents = jsonObj;
yaml = doc.toString();

console.log(yaml);


This content originally appeared on DEV Community and was authored by DEV Community


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2022-03-10T03:29:23+00:00) Snippets… JSON. Retrieved from https://www.scien.cx/2022/03/10/snippets-json/

MLA
" » Snippets… JSON." DEV Community | Sciencx - Thursday March 10, 2022, https://www.scien.cx/2022/03/10/snippets-json/
HARVARD
DEV Community | Sciencx Thursday March 10, 2022 » Snippets… JSON., viewed ,<https://www.scien.cx/2022/03/10/snippets-json/>
VANCOUVER
DEV Community | Sciencx - » Snippets… JSON. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/10/snippets-json/
CHICAGO
" » Snippets… JSON." DEV Community | Sciencx - Accessed . https://www.scien.cx/2022/03/10/snippets-json/
IEEE
" » Snippets… JSON." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2022/03/10/snippets-json/. [Accessed: ]
rf:citation
» Snippets… JSON | DEV Community | Sciencx | https://www.scien.cx/2022/03/10/snippets-json/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.