Jump to main content Jump to doc navigation

xPDOObject::fromJSON()

Sets the object fields from a JSON object string.

Syntax

API Docs: https://api.modx.com/revolution/2.2/db_core_xpdo_om_xpdoobject.class.html

void fromJSON (
   string $jsonSource,
   [string $keyPrefix = ''],
   [boolean $setPrimaryKeys = false],
   [boolean $rawValues = false],
   [boolean $adhocValues = false]
)

Example

$str = '{"name":"Sirius","email":"Black"}';
$object->fromJSON($str);
echo $object->get('name').' '.$object->get('email');
// prints "Sirius Black"

See Also