JSON is an extremely common and powerful way of exchanging data across the Internet. It benefits from being lightweight and easy to parse. This first post shows you the basic principles of working with JSON and a second (later) post will extend this discussion to show how JSON is likely to be encountered in the real world and how we begin to work with it when we do encounter it in the real world. The littlest JavaScript object First lets create a JavaScript object in a regular HTML document (saved as always in a regular text editor – not word processor – with a HTML extension). <!DOCTYPE html> <html> <head></head> <body> <script>var object = {};</script> </body> </html> The name object isn't important (it could be anything – e.g. potato), but var is essential and so too are the curly braces {} and semi-colon. Adding properties (keys) and values Now we're going to add a property to the object. Let's for
Technology tips for writers, editors, designers, illustrators, programmers and publishers, and now Retro Gamers.