#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
HTTP

JSON Data Representation

JSON (JavaScript Object Notation) is a text format for representing structured data, and it is the standard way web APIs send and receive information. It looks almost exactly like JavaScript object literals, which makes it easy to read, but it has stricter rules. Any language, from Python to Java, can parse it, so it works as a common language between frontends and backends.

The six value types

JSON supports only a small set of value types:

  • String: always in double quotes, such as "Asha".
  • Number: integers or decimals like 42 or 3.5; no leading zeros, no NaN or Infinity.
  • Boolean: true or false.
  • Null: null for "no value".
  • Object: key-value pairs in curly braces, where every key is a double-quoted string.
  • Array: an ordered list of values in square brackets.

Objects and arrays can be nested inside each other to any depth, which is how complex data such as an order with a customer and a list of items is represented.

{
  "orderId": 1087,
  "paid": true,
  "coupon": null,
  "customer": {
    "name": "Asha Verma",
    "email": "asha@example.com"
  },
  "items": [
    { "sku": "LAMP-01", "qty": 1, "price": 899.5 },
    { "sku": "BULB-04", "qty": 3, "price": 120 }
  ]
}

How JSON differs from a JavaScript object

RuleJavaScript objectJSON
KeysQuotes optionalDouble quotes required
StringsSingle, double or backtick quotesDouble quotes only
Trailing commasAllowedNot allowed
CommentsAllowedNot allowed
Functions, undefined, datesAllowedNot supported

Because JSON has no date type, dates are usually sent as ISO 8601 strings in the pattern "YYYY-MM-DDTHH:mm:ssZ", produced by date.toISOString(), and converted back with new Date(value) after parsing.

Converting between JSON and JavaScript

JSON.stringify(value) turns a JavaScript value into a JSON string, ready to send in a request body. Pass extra arguments, as in JSON.stringify(data, null, 2), to get indented, readable output. JSON.parse(text) does the reverse. When using fetch, await response.json() parses the body for you, and when sending you set the Content-Type: application/json header so the server knows what it is receiving.

Errors you will run into

"Unexpected token" errors from JSON.parse almost always mean the text is not valid JSON. Typical causes are single quotes, a trailing comma after the last item, or, very often, the server returning an HTML error page instead of JSON. If you see "Unexpected token <", the first character was the start of an HTML tag; check the network tab to see what the server actually sent.

Another surprise is that JSON.stringify silently drops properties whose value is undefined or a function, and turns NaN into null. Very large integers can also lose precision when parsed, since JavaScript numbers are floating point, so IDs beyond the safe integer range are best sent as strings.

Designing clear JSON

Pick one naming style, usually camelCase, and stick to it. Use arrays for lists even when there is only one item, so clients do not have to check the type. Use null deliberately for "known to be empty" rather than leaving fields out at random.

Takeaway: JSON uses six value types with double-quoted keys and strings, has no comments, trailing commas or dates, and is converted with JSON.stringify and JSON.parse.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course