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?

  • 4
    What's the alternative? Inventing your own data format? – user7043 Dec 18 '12 at 19:10
  • @delnan: Yaml, CSV. I could probably think of a few others. – Robert Harvey Dec 18 '12 at 19:17
  • 10
    Rarely is using blah for the sake of using blah a wise plan. Look at the things JSON is good for, and then consider whether its worth using JSON for those specific aspects. – whatsisname Dec 18 '12 at 19:19
  • @RobertHarvey: Or, standard HTTP forms. – cHao Dec 18 '12 at 19:28
  • 7
    I'm building a blogging site for learning - your learning the associated technologies? or to provide material for others? If the former, absolutely - use json for the sake of using it so you learn to use it. Challenge yourself with new technologies - otherwise, you won't learn how to use them. – user40980 Dec 18 '12 at 19:44

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.

  • 6
    in the speaking with JS part do not ever use eval to get the value of it instead use JSON.parse available in most browsers – ratchet freak Dec 18 '12 at 19:17
  • 1
    It speaks easily to PHP as well, since json_decode() and json_encode() convert between a JSON string and the native Array() data structure – Izkata Dec 18 '12 at 21:11
  • @Izkata only if your server has those functions. – Darth Egregious Dec 18 '12 at 21:32
  • Except in the case of form submission, using JSON breaks standards. Why fix what's not broken? – Reinstate Monica Dec 18 '12 at 21:39
  • 2
    @BrendanLong: That standard doesn't say anything about using or not using JSON. Obviously if you're doing a form submission, you should encode all data according to the HTTP standard. But if one of the form elements you're sending is a complex item containing multiple semantic elements, putting that element in JSON format (which is then encoded correctly by your HTTP library) is a good way to do it. – Mason Wheeler Dec 18 '12 at 21:43

For what you describe - it sounds like a blogging platform where everything is submitted via forms - no, you dont need to convert it all to JSON. PHP handles forms seamlessly for you. There's no reason to introduce a new piece of complication in that situation.

Again, in your specific circumstance, JSON might be something you'd use if you needed to send semi-structured data back to the web brower. On the browser side, the JSON would be very easy to parse out in javascript.


JSON is only useful if you intend to make a JavaScript heavy site that uses Ajax requests to pass data to the server/get data to display without doing a full post-back. If you have no intention of making use of that functionality using JSON is just wrapping your code in another layer that has to be serialized/deserialized to do anything useful.


I don't think implementing JSON will inherently improve your site as is. JSON is JavaScript Object Notation; so unless you're starting to learn JavaScript as well, I don't see an inherent value in making sure everything is in JSON.

  • You don't need to learn JavaScript to use/abuse JSON. It's language-independent. – CokoBWare Dec 18 '12 at 20:36

While JSON is very extensible and well-structured, it's not the fastest one.

JSON is great for sending data from server to clients, because it resolves issues with encoding.

But on the server, you need maximum performance and minimum disc space consumption. So, for tables, you should use MySQL columns, and for non-tables a binary format is preferred.

To solve extensibility issues with binary files, you can tag your structures with a 4-character code for structure name and 1-2-byte number for version.

  • 6
    JSON is a data format, not a database. – Robert Harvey Dec 18 '12 at 19:16
  • Yes, but it can be used to store arrays. – Triang3l Dec 18 '12 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.