So it's saying that the variable info is defined but never used, and that's really not an error; it's just that it's super opinionated and because I've just created a variable that I'm not calling--because that's not a real page like this is not a real quote that I'm going to use in a real program. It's just a demo to show you how to access a variable. It's complaining that I'm actually not using this variable anywhere. So you can actually modify this tool to not be as picky as it normally is. So you could maybe click off when a variable is undefined or a variable is defined but not used.
So I need to modify this to make sure that it doesn't have a semicolon and it doesn't have the variable. So I'll hit Validate, and it's telling me that it's a valid JSON. This would be really cool if you were trying to make sure that you didn't do something like forget one of these quotes and when you hit Validate, it's going to try to find the error for you and tell you that there is an error on line 6. So this is a really good idea to check if you're typing in your own JSON, to make sure that you've done everything correctly. Also if your JSON is being generated by some sort of PHP script, then you can pass that along here and it will verify that you've made all the changes correctly.
Notice that you can also put a URL. So if you're trying to check the validity of a PHP script that generates JSON, then you can just paste the URL and it will check that as well. So by far, my favorite editor is actually something called JSON Editor Online. You can see it right here. It's super powerful. It already gives you some sample data so you could see that you could traverse objects just like you can in the console, and you can make modifications to things. So you can say here Pete Smith, and you can go from this side of the screen to the other side of the screen, so you can make the modifications permanently in your JSON document by hitting this button, or you can modify something here and hit this button and it will transfer to this view right here.
So you can look at the object just like you would in the console. Plus, it has a lot of other really cool options. So another thing that I like is that it lets you just minify your JSON. It takes care of removing all the white spaces by hitting this button right here. You can also add the spaces back in, kind of indent everything properly, by hitting this button. So this is actually an excellent tool for checking out your schema, the structure of your JSON documents, as you're designing them.
There are also a couple of tools that you can use offline. You should always have an offline tool, just in case you're on a plane trip or you're not sure what kind of connectivity or you're visiting your cousin from Topeka who doesn't have a connection or somebody that has a really slow connection. So you probably want to find some sort of offline editor. I like this one for the Mac called Cocoa JSON Editor. It's a really good tool for looking at the structure of your JSON data, and it's excellent for working offline. It's even great for working online, but since I found the JSON Online Editor, I don't really use it as much as I used to.
Then there is a PC version here called JSONPad. It's not quite a slick as Cocoa JSON Editor, but it will do if you're on a PC. There are other tools that you can use to add some JSON functionality to your browsers. There's a great tool called JSONView, available for Firefox at this URL, and in the Chrome web store at this URL right here. So these are both tools that will expand the capabilities of your browser to be able to see some of the JSON files directly. So when you pull your JSON document to your browser, it's going to look really nice, and you're going to be able to visualize it a lot better.
- What is JSON?
- Creating simple data
- Communicating across sites with JSONP
- Rotating with jQuery Cycle