You are previewing JavaScript JSON Cookbook.
O'Reilly logo
JavaScript JSON Cookbook

Book Description

Over 80 recipes to make the most of JSON in your desktop, server, web, and mobile applications

In Detail

JSON (JavaScript Object Notation) is a lightweight text-based data interchange format used to create objects to transfer data over the Internet. It's widely used today by common web applications, as well as mobile applications.

This book gives you clear ways that you can exchange objects using JSON, regardless of whether you're developing a web or traditional networked application. You'll start with a brief refresher on JSON and JavaScript syntax and read and write on the client and server. Then, you'll learn how to use JSON in simple AJAX applications using AngularJS and jQuery. Next, you will learn how to exchange objects with databases using MongoDB and CouchDB. You'll also explore how to use JSON in a type-safe manner, writing programs that have fewer bugs.

What You Will Learn

  • Learn to use JSON in a type-safe way to avoid common data typing errors

  • Exchange data with NoSQL databases such as MongoDB and CouchDB with JSON

  • Make the most of JSON in AJAX web applications, with or without a framework

  • Exchange data between servers and mobile applications running on Android and iOS with JSON

  • Practical examples to show you how to leverage JSON from a variety of application domains

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. JavaScript JSON Cookbook
      1. Table of Contents
      2. JavaScript JSON Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Reading and Writing JSON on the Client
        1. Introduction
        2. Reading and writing JSON in JavaScript
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Reading and writing JSON in C++
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Reading and writing JSON in C#
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Reading and writing JSON in Java
          1. Getting ready
          2. How to do it...
          3. There's more…
          4. See also
        6. Reading and writing JSON in Perl
          1. How to do it...
          2. How it works...
          3. See also
        7. Reading and writing JSON in Python
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      9. 2. Reading and Writing JSON on the Server
        1. Reading and writing JSON in Clojure
          1. Getting ready
          2. How to do it...
          3. There's more...
        2. Reading and writing JSON in F#
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Reading and writing JSON with Node.js
          1. Getting ready
          2. How to do it...
          3. See also
        4. Reading and writing JSON in PHP
          1. How to do it...
        5. Reading and writing JSON in Ruby
          1. Getting ready
          2. How to do it...
          3. See also
      10. 3. Using JSON in Simple AJAX Applications
        1. Introduction
          1. Setting up the server
          2. Setting up the client page
        2. Creating an XMLHttpRequest object
          1. How to do it...
          2. How it works…
          3. See also
        3. Making an asynchronous request for data
          1. How to do it...
          2. How it works…
          3. See also
        4. Sending JSON to your web server
          1. How to do it...
          2. How it works…
        5. Accepting JSON using Node.js
          1. How to do it...
          2. How it works…
          3. See also
        6. Getting the progress of an asynchronous request
          1. How to do it...
          2. How it works…
          3. There's more...
          4. See also
        7. Parsing the returned JSON
          1. How to do it...
          2. How it works…
          3. There's more...
        8. Issuing a web service request using Node.js
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more...
          5. See also
      11. 4. Using JSON in AJAX Applications with jQuery and AngularJS
        1. Introduction
        2. Adding a dependency to jQuery to your web page
          1. How to do it...
          2. How it works…
          3. There's more…
          4. See also
        3. Requesting JSON content using jQuery
          1. How to do it...
          2. How it works…
          3. See also
        4. Sending JSON to your web server using jQuery
          1. How to do it...
          2. How it works…
        5. Getting the progress of a request using jQuery
          1. How to do it...
          2. How it works…
          3. There's more...
        6. Parsing the returned JSON using jQuery
          1. How to do it...
          2. How it works…
          3. There's more...
        7. Adding a dependency to AngularJS to your web page
          1. How to do it...
          2. How it works…
          3. See also
        8. Requesting JSON content using AngularJS
          1. How to do it...
          2. How it works…
          3. There's more...
          4. See also
        9. Sending JSON to your web server using AngularJS
          1. How to do it...
          2. How it works…
          3. There's more...
        10. Getting the progress of a request using AngularJS
          1. How to do it...
          2. How it works…
        11. Parsing the returned JSON using AngularJS
          1. How to do it...
          2. How it works…
      12. 5. Using JSON with MongoDB
        1. Introduction
        2. Setting up MongoDB
          1. How to do it…
          2. How it works…
        3. Installing the MongoDB database driver for Node.js
          1. How to do it…
        4. Installing the express module for Node.js
          1. How to do it…
          2. How it works…
          3. See also
        5. Connecting to a MongoDB database using Node.js
          1. How to do it...
          2. How it works…
          3. See also
        6. Creating a document in MongoDB using Node.js
          1. How to do it...
          2. How it works…
          3. There's more
          4. See also
        7. Searching for a document in MongoDB with Node.js
          1. How to do it...
          2. How it works…
          3. There's more
          4. See also
        8. Updating a document in MongoDB with Node.js
          1. How to do it...
          2. How it works…
          3. There's more…
          4. See also
        9. Deleting a document in MongoDB using Node.js
          1. How to do it...
          2. How it works…
          3. See also
        10. Using REST to search MongoDB
          1. How to do it...
          2. How it works…
          3. There's more
        11. Using REST to create a document in MongoDB
          1. How to do it...
          2. How it works…
        12. Using REST to update a document in MongoDB
          1. How to do it...
          2. How it works…
        13. Using REST to delete a document in MongoDB
          1. How to do it...
          2. How it works…
      13. 6. Using JSON with CouchDB
        1. Introduction
        2. Installing and setting up CouchDB and Cradle
          1. How to do it…
          2. How it works…
          3. See also
        3. Connecting to a CouchDB database using Node.js and Cradle
          1. How to do it...
          2. How it works…
        4. Creating a CouchDB database using Node.js and Cradle
          1. How to do it...
          2. How it works…
          3. There's more…
        5. Creating a document in CouchDB using Node.js and Cradle
          1. How to do it...
          2. How it works…
        6. Setting up a data view in CouchDB with Node.js and Cradle
          1. How to do it...
          2. How it works…
          3. See also
        7. Searching for a document in CouchDB with Node.js and Cradle
          1. How to do it...
          2. How it works…
          3. There's more
          4. See also
        8. Updating a document in CouchDB with Node.js and Cradle
          1. How to do it...
        9. Deleting a document in CouchDB using Node.js and Cradle
          1. How to do it...
          2. There's more…
        10. Using REST to enumerate CouchDB records
          1. How to do it...
          2. How it works…
          3. See also
        11. Using REST to search CouchDB
          1. How to do it...
          2. How it works…
        12. Using REST to upsert a document in CouchDB
          1. How to do it...
          2. How it works…
        13. Using REST to delete a document in CouchDB
          1. How to do it…
          2. How it works…
      14. 7. Using JSON in a Type-safe Manner
        1. Introduction
        2. How to deserialize an object using Json.NET
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        3. How to handle date and time objects using Json.NET
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        4. How to deserialize an object using gson for Java
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. How to use TypeScript with Node.js
          1. How to do it…
          2. There's more…
          3. See also
        6. How to annotate simple types using TypeScript
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        7. How to declare interfaces using TypeScript
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        8. How to declare classes with interfaces using TypeScript
          1. How to do it…
          2. How it works…
          3. See also
        9. Using json2ts to generate TypeScript interfaces from your JSON
          1. How to do it…
          2. How it works…
      15. 8. Using JSON for Binary Data Transfer
        1. Introduction
        2. Encoding binary data as a base64 string using Node.js
          1. How to do it…
          2. How it works…
          3. See also
        3. Decoding binary data from a base64 string using Node.js
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Encoding and decoding binary data as a base64 string using JavaScript in the browser
          1. How to do it…
          2. How it works…
          3. See also
        5. Encoding data as BSON using Json.NET
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Decoding data from BSON using Json.NET
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        7. Using a DataView to access an ArrayBuffer
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. Encoding and decoding base64 using an ArrayBuffer
          1. How to do it…
          2. How it works…
        9. Compressing object-body content from a Node.js server built using the express module
          1. Getting ready
          2. How to do it…
          3. How it works…
      16. 9. Querying JSON with JSONPath and LINQ
        1. Introduction
        2. Using the JSONPath dot-notation to query JSON documents
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        3. Using JSONPath bracket-notation to query JSON documents
          1. How to do it…
          2. How it works…
        4. Using JSONPath scripting to construct more complicated queries
          1. How to do it…
          2. How it works…
        5. Using JSONPath in your web application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Using JSONPath in your Node.js application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        7. Using JSONPath in your PHP application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. Using JSONPath in your Python application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        9. Using JSONPath in your Java application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        10. Using JSONPath with SelectToken to query for JSONPath expressions in your C# application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        11. Using LINQ with Json.NET to query JSON in your C# application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      17. 10. JSON on Mobile Platforms
        1. Introduction
        2. Parsing JSON on Android
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        3. Generating JSON on Android
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        4. Parsing JSON on iOS in Objective-C
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        5. Generating JSON on iOS in Objective-C
          1. How to do it…
          2. How it works…
          3. See also
        6. Parsing JSON on iOS using Swift
          1. How to do it…
          2. How it works…
        7. Generating JSON on iOS using Swift
          1. How to do it…
          2. How it works…
        8. Parsing JSON using Qt
          1. How to do it…
          2. How it works…
          3. There's more…
          4. See also
        9. Generating JSON using Qt
          1. How to do it…
          2. How it works…
          3. See also
      18. Index