Chapter 27. Zend_Json

Table of Contents

27.1. Introduction
27.2. Basic Usage
27.3. Advanced Usage of Zend_Json
27.3.1. JSON Objects
27.3.2. Encoding PHP objects
27.3.3. Internal Encoder/Decoder
27.3.4. JSON Expressions
27.4. XML to JSON conversion
27.5. Zend_Json_Server - JSON-RPC server
27.5.1. Advanced Details
27.5.1.1. Zend_Json_Server
27.5.1.2. Zend_Json_Server_Request
27.5.1.3. Zend_Json_Server_Response
27.5.1.4. Zend_Json_Server_Error
27.5.1.5. Zend_Json_Server_Smd

27.1. Introduction

Zend_Json provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP. For more information on JSON, visit the JSON project site.

JSON, JavaScript Object Notation, can be used for data interchange between JavaScript and other languages. Since JSON can be directly evaluated by JavaScript, it is a more efficient and lightweight format than XML for exchanging data with JavaScript clients.

In addition, Zend_Json provides a useful way to convert any arbitrary XML formatted string into a JSON formatted string. This built-in feature will enable PHP developers to transform the enterprise data encoded in XML format into JSON format before sending it to browser-based Ajax client applications. It provides an easy way to do dynamic data conversion on the server-side code thereby avoiding unnecessary XML parsing in the browser-side applications. It offers a nice utility function that results in easier application-specific data processing techniques.