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?
8
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
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.
1
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.
2