Exposes an API that allows developers to write-to, and query-from JSON data from a dedicated
In addition, if your project uses the
silverstripe/cms package, then you can extend arbitrary
DataObject's to allow multiple, arbitrary UI fields as declared in
getCMSFields(), to write to a JSON object in a single database field.
Using JSONPath (Think XPath but for JSON) and the module's extensive API, developers can selectively target specific JSON keys for modification.
nth()or Postgres-like operators:
#>or even JSONPath expressions.
Arrayor cast to SilverStripe's
The module exposes a fully featured JSON query and update API allowing developers to use XPath-like queries via JSONPath
or Postgres' JSON operators (with some differences, see below) to query and update JSON data.
Intdatabase columns just seems crazy.
In Postgres both the
->> operators act as string and integer key matchers on a JSON array or JSON object respectively. The module
however treats both source types the same - they are after all both JSON so
-> is used as an Integer Matcher and
->> as a String Matcher
regardless of the "type" of source JSON stored. The
#> Path Matcher operator can act as an object or a text matcher, but the module wishes to simplify things and as such
#> operator is just a simple path matcher.
Regardless of the type of query you can set what type you'd like the data returned in via the
setReturnType() method on a query by query basis.
Legitimate types are:
SilverStripe as the return type, the module will automatically cast the result(s) to one of SilverStripe's
If there are multiple results from a query, the output will be an indexed array containing a single-value array for each result found.
The module also allows developers to selectively update all, or just parts of the source JSON, via JSONPath expressions passed
to an overloaded
See the usage docs for examples of JSONPath and Postgres querying and updating.
Note: This module's query API is based on a relatively simple JSON to array conversion principle.
It does not use Postgres' or MySQL's native JSON operators at or below the level of the ORM. The aim
is to allow dev's to use their preferred DB's syntax, and to this end you can set
the module into
postgres mode using YML config, see Configuration Docs.
#> composer require phptek/silverstripe-jsontext
See: Configuration Docs.
See: Usage Docs.
If you've been using Postgres or MySQL with its JSON functions for some time,
I'm keen to hear from you. Some simple failing tests would be most welcome.
Please include all details, no matter how small. If it were your module, what would you need to know from a bug/feature request? :-)
Russell Michell 2016-2019 [email protected]
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem