Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Json Data Types in JavaScript

Json Data Types in JavaScript

JSON Data Types in JavaScript

JSON (JavaScript Object Notation) supports a limited set of data types, which correspond closely to JavaScript data types.


JSON Data Types

JSON TypeDescriptionExampleJavaScript Equivalent
StringText wrapped in double quotes"Hello World"String
NumberNumeric values (integer or floating-point)42, 3.14Number
Booleantrue or falsetrue, falseBoolean
NullRepresents a null valuenullnull
ArrayOrdered list of values inside [ ][1, "two", false]Array
ObjectCollection of key/value pairs inside { }{"name":"John", "age":30}Object

Examples of JSON Data Types

{  "name": "Alice",           // String  "age": 25,                // Number  "isStudent": false,       // Boolean  "hobbies": ["reading", "gaming"],  // Array  "address": {              // Object    "city": "New York",    "zip": "10001"  },  "spouse": null            // Null}

Using JSON Data Types in JavaScript

Parsing JSON String to JavaScript Object

const jsonString = `{  "name": "Alice",  "age": 25,  "isStudent": false,  "hobbies": ["reading", "gaming"],  "address": {"city": "New York", "zip": "10001"},  "spouse": null}`;const obj = JSON.parse(jsonString);console.log(obj.name);        // "Alice"console.log(obj.age);         // 25console.log(obj.isStudent);   // falseconsole.log(obj.hobbies[0]);  // "reading"console.log(obj.address.city);// "New York"console.log(obj.spouse);      // null

Converting JavaScript Object to JSON String

const person = {  name: "Alice",  age: 25,  isStudent: false,  hobbies: ["reading", "gaming"],  address: {city: "New York", zip: "10001"},  spouse: null};const jsonStr = JSON.stringify(person);console.log(jsonStr);

If you'd like, I can help with examples on how to work with each type in real code or how to validate JSON data!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql