When Laravel meets json
If you know the name Douglas Crockford, you know JSON. Mr Crockford is a Chuck Norris of sorts in the Javascript world and created the JSON standard. It stands for JavaScript Object Notation and it provides a great way to share data between languages and applications. Douglas I’m sure is proud of his baby, and we can thank him for declaring himself a standards body and bringing JSON into existence. Let’s learn a little more about JSON in Laravel!
Why JSON? When dealing with data transfer, we need a convenient method of markup. XML was the first way to accomplish this, but now we are seeing a major uptake of JSON. Why? Because JSON is very easy to read and convenient for storing arrays and objects with values as strings.
AJAX is a popular method of using JSON. Let’s say you make an AJAX hit on your application from the front end, often times the server side will respond with JSON as that data can now be easily parsed and integrated into the Javascript front end. It’s quite magical in fact! If you have ever used the Twitter API, you will also notice that JSON is their method of data exchange.
In PHP we have some nifty functions named json_encode() and json_decode() and Laravel makes great use of these. Let’s now take a look at some JSON!
note: If you are using Firefox you may need to install an add-on like JSONview to make the JSON output pretty in the browser.
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5 Laravel 5.1