Serialization of PHP data to a native JavaScript representation

Related links

This PHP library provides a simple, dependency-free serialization of a PHP variable value / datastructure to strings which can be interpreted as a JavaScript value.

The most typical use case will be the automated generation of JavaScript code in cases where the amount of data is notably and therefore serializing to JSON would suffer from the deserialization penalty and/or the larger size of JSON data.

The following datatypes can be handled:

null

string

float

int

array

object – if the object implements the JsonSerializable interface, has a public toArray() method or has a public __toString() method. (The mentioned order is exactly the order in which the code performs the checks.)