Skip to content
Greg Bowler edited this page Mar 28, 2023 · 6 revisions

Throughout PHP.Gt libraries, wherever an object is used to represent data, the DataObject library is used. Instances of DataObject provide structured, type-safe, immutable data transfer.

This library extends DataObject by adding JSON-specific functionality. The main usage will be via the JsonObjectBuilder class that can be used to build a type of JsonObject from any JSON string or decoded JSON object from json_decode.

The purpose of using these classes to represent decoded JSON data is to provide a type-safe, immutable interface to the enclosed data.

A typical example

The following JSON string is taken from the Stripe API documentation as example data to work with.

$jsonString:

{
	"object": "balance",
	"available": [
		{
			"amount": 2217713,
			"currency": "cad",
			"source_types": {
				"bank_account": 0,
				"card": 2217713
			}
		},
		{
			"amount": 7254790,
			"currency": "gbp",
			"source_types": {
				"bank_account": 0,
				"card": 7254790
			}
		}
	]
}
Clone this wiki locally