Úryvky... JSON

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

Řetězec JSON na objekt JSON

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

Objekt JSON na řetězec JSON

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

Objekt JSON na řetězec Base64

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

Řetězec parametru JSON Object to URL

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

console.log(urlParams);

JSON Objekt YAML pomocí yaml

Nainstalujte balíček yaml z NPM, více se o tomto balíčku dozvíte zde.

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