JSON – Should I Use JSON Just to Use JSON?

jsonPHP

I'm building a blogging site for learning, with a PHP/MySQl back-end. All of the user input is handled with forms sent in POST requests.

Will using JSON somehow make it cleaner, or easier to maintain or add features? Or am I just adding an interchange format for no reason?

So essentially, what functionality would be best implemented by using JSON?

Best Answer

JSON has a few advantages:

  • It's a structured format, which can be validated and parsed with existing, mature tools.
  • It can speak easily to JavaScript, which makes it very useful for AJAX communication.
  • It's extremely simple and lightweight. Anything you'd want to use XML data interchange for, JSON is generally a better alternative.

My rule of thumb is, if you only need to return a single semantic element from a call, send it as plain text. But if you need to return multiple pieces of information, use JSON.

Related Topic