ornament/json

JSON model for the Ornament ORM framework

Installs: 473

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 1

pkg:composer/ornament/json

0.16.0 2025-03-02 13:11 UTC

README

JSON helpers for Ornament ORM

Installation

$ composer require ornament/json

Usage

This packaged provides the Json decorator, which automagically calls json_decode on a string value (storage drivers usually don't do that for you). The decorator throws a DomainException if the string passed is not valid JSON. If the value input is not a string, it is used verbatim.

Additionally, it provides two helpful traits: SerializeAll and SerializeOnlyPublic. The first makes the property serializable; the second also, but only exposes the public properties.

Caveats

While null is a valid value to encapsulate in a JSON string, it is assumed that this value is not valid. The decoded JSON should be either an object or an array - encoding null as JSON in a storage engine just doesn't... make a lot of sense.