A Brief Overview of JSON

JSON stands for JavaScript Object Notation. It’s the text format used for sharing data, and is the most popular data transmission format. JSON is used for local data while JSONP is used for remote data.

Here are a few other things to keep in mind about this data format:

  • JSON is language independent (it’s available in php, Python, etc)
  • JSON keys are wrapped in quotes
  • JSON keys can be any valid string
  • Special characters can make it difficult to access data, and you should use underscores instead of hyphens
  • JSON has to be parsed into JavaScript (which can be done with eval or JSON.parse – JSON.stringify does the opposite of parse)
  • A great alternative to XML

JSONP

  • Stands for JSON with padding
  • Used for cross domain requests
  • Request URL incorporates the name of a callback function according to syntax defined by the service you’re using

Response Formats

  • JSON object
  • JSON array
  • JSONP (function)
  • Browsers enforce same-origin policy

Cross-Site Script Injection (XSSI)

  • Protecting against XSSI – can strip out malformed code
  • If downloaded directly, it isn’t parsed and creates an error

Alternatives to JSON

XML

  • Extensible Markup Language
  • Was widely used before JSON became popular
  • We can convert JSON to XML with different services

YAML

  • Was created to be human readable
  • Another language used to interchange data on the web
  • Uses white space, including indents and blank lines, which increases the size of YAML but makes it easier for humans to read
  • Uses key value pairs
  • Strings don’t need to be quoted
  • Supports explicit data typing
  • Supports single-line comments that are denoted by # (JSON doesn’t allow commenting)
  • JSON is good for basic use cases and has parsing built into JavaScript, while YAML is not directly usable in JavaScript

Leave a Reply