Book Image

JavaScript JSON Cookbook

By : Ray Rischpater, Brian Ritchie, Ray Rischpater
Book Image

JavaScript JSON Cookbook

By: Ray Rischpater, Brian Ritchie, Ray Rischpater

Overview of this book

Table of Contents (17 chapters)
JavaScript JSON Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introduction


There are typically two reasons why you might want to think about binary representation when using JSON: either because you need to carry binary data between one part of your application to another or because you're worried about the size of the JSON you're transporting.

In the first case, you're actually a little stuck, as the existing JSON specification doesn't provide a container format for binary data because JSON is a text-based representation of data at its heart. You can choose to encode binary data in another format, such as base64, which renders binary data as a printable character string, or you can use an extension of JSON, such as Binary JSON (BSON), that supports Binary data.

BSON uses the semantics of JSON but represents the data in a binary form. Thus, the same basic structure is available: a (possibly nested) map of key-value pairs, where values can be other key-value pairs, arrays, strings, or even binary data. However, instead of using plaintext encoding, the...