PHPackages                             phptek/jsontext - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. phptek/jsontext

ActiveSilverstripe-vendormodule[Parsing &amp; Serialization](/categories/parsing)

phptek/jsontext
===============

JSON storage, querying and modification.

2.1.0(6y ago)2222.2k13[7 issues](https://github.com/phptek/silverstripe-jsontext/issues)2BSD-3-ClausePHPPHP &gt;=5.6.0

Since Jun 15Pushed 1y ago3 watchersCompare

[ Source](https://github.com/phptek/silverstripe-jsontext)[ Packagist](https://packagist.org/packages/phptek/jsontext)[ RSS](/packages/phptek-jsontext/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (17)Used By (2)

SilverStripe JSONText
=====================

[](#silverstripe-jsontext)

[![Build Status](https://camo.githubusercontent.com/88076f9767326a1252398a2a8b81aa102c6feef210c7a614968c797a6fd6c316/68747470733a2f2f6170692e7472617669732d63692e6f72672f70687074656b2f73696c7665727374726970652d6a736f6e746578742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phptek/silverstripe-jsontext)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/729cf39e249e055dadaa88ad768fb9ee8e5550349c2dd394269fe5e8865fbd94/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70687074656b2f73696c7665727374726970652d6a736f6e746578742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phptek/silverstripe-jsontext/?branch=master)[![License](https://camo.githubusercontent.com/dcf95d1d47b030c454126925a2b7baa0bafe6d4d9e4df00b53ba2cc647cf5a7d/68747470733a2f2f706f7365722e707567782e6f72672f70687074656b2f6a736f6e746578742f6c6963656e73652e737667)](https://github.com/phptek/silverstripe-jsontext/blob/master/LICENSE.md)

Exposes a complete API that allows developers to write-to, and query-from JSON in a dedicated `DBField` subclass.

In addition, if your project uses the `silverstripe/cms` package, then all `SiteTree` objects are automatically extended 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.

Requirements
------------

[](#requirements)

### SilverStripe 4

[](#silverstripe-4)

- Use ^2.0
- PHP &gt;=5.6, &lt;=7.1

### SilverStripe 3

[](#silverstripe-3)

- Use ^1.0
- PHP &gt;=5.4, &lt;7.0

Features
--------

[](#features)

- Store JSON "object-strings" in a JSON-specific `DBField` subclass.
- Query stored JSON via simple accessors: `first()`, `last()` &amp; `nth()` or Postgres-like operators: `->`, `->>` &amp; `#>` or even [JSONPath](http://goessner.net/articles/JsonPath/) expressions.
- Selectively return query-results as `JSON`, `Array` or cast to SilverStripe's `DBVarchar`, `DBInt`, `DBFloat` or `DBBoolean` objects.
- Selectively update portions of stored JSON using [JSONPath](http://goessner.net/articles/JsonPath/) expressions.
- Selectively transform one or more CMS input fields, to write to a single JSON store.

Introduction
------------

[](#introduction)

The module exposes a fully featured JSON query and update API allowing developers to use XPath-like queries via [JSONPath](http://goessner.net/articles/JsonPath/)or [Postgres' JSON operators](https://www.postgresql.org/docs/9.5/static/functions-json.html) (with some differences, see below) to query and update JSON data.

### Why?

[](#why)

Project scenarios where storing 10s of terse configuration parameters as Booleans and Ints in separate database columns just seems crazy.

When all you wanted was a simple key / value store but didn't want to muck about with the overhead of an RDBMS *and* a NOSQL DB.

That Postgres, MySQL, Oracle and MSSQL 2016 all have, or at time of writing, are planning to have, Database level JSON field-types. This module plugs the gap for users of RDBMS' *without* native JSON support, while offering the a convenient scaffold on top of which native JSON support could be built.

### Postgres

[](#postgres)

In Postgres both the `->` and `->>` 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 the `#>` operator is *just a simple path matcher*.

### Return types

[](#return-types)

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:

- JSON
- Array
- SilverStripe

If using `SilverStripe` as the return type, the module will automatically cast the result(s) to one of SilverStripe's `DBObject` subtypes:

- `DBBoolean`
- `DBInt`
- `DBFloat`
- `DBVarchar`

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 `setValue()` method.

See [the usage docs](docs/en/usage.md) 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 however is to allow dev's to use their preferred DB's syntax, and to this end you can set the module into `mysql` or `postgres` mode using SS config, see [Configuration Docs](docs/en/configuration.md).

Installation
------------

[](#installation)

```
#> composer require phptek/jsontext

```

Configuration
-------------

[](#configuration)

See: [Configuration Docs](docs/en/configuration.md).

Usage
-----

[](#usage)

See: [Usage Docs](docs/en/usage.md).

Contributing
------------

[](#contributing)

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.

See: [CONTRIBUTING.md](CONTRIBUTING.md).

Reporting an issue
------------------

[](#reporting-an-issue)

Please include all details, no matter how small. If it were *your module*, what would you need to know from a bug/feature request? :-)

Credits
-------

[](#credits)

- [Axel Anceau](https://github.com/Peekmo/) for his packaging-up of the pretty amazing JSONPath implementation by [Stefan Goessner](https://code.google.com/archive/p/jsonpath/)
- [Stefan Goessner](https://code.google.com/archive/p/jsonpath/) for the original work on JSONPath dating back to 2005!

Author
------

[](#author)

Russell Michell 2016-2018

TODO
----

[](#todo)

- Add missing `prepValueForDB()` to `JSONText` class.
- See official list of issues on GitHub.

Support Me
----------

[](#support-me)

If you like what you see, support me! I accept Bitcoin:

   [![Bitcoin](https://camo.githubusercontent.com/bf9c656e311cb8e1c8f7d578156a9e405cf337b889d0ad436f876f06dc0c36a5/68747470733a2f2f626974636f696e2e6f72672f696d672f69636f6e732f6c6f676f5f696f732e706e67)](https://camo.githubusercontent.com/bf9c656e311cb8e1c8f7d578156a9e405cf337b889d0ad436f876f06dc0c36a5/68747470733a2f2f626974636f696e2e6f72672f696d672f69636f6e732f6c6f676f5f696f732e706e67)     **3KxmqFeVWoigjvXZoLGnoNzvEwnDq3dZ8Q**

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 99% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Recently: every ~118 days

Total

16

Last Release

2465d ago

Major Versions

0.7 → 1.02017-04-09

1.0.1 → 2.0.0-alpha12017-05-03

1.0.2 → 3.0.x-dev2019-08-18

PHP version history (3 changes)0.1PHP &gt;=5.4,&lt;7

2.0.0-alpha1PHP &gt;=5.6.0

1.0.2PHP &gt;=5.4,&lt;7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/30dea83801428834fb2e1bee1e6e2925e5d7876877fef189dc7f6c8f2878af14?d=identicon)[phptek](/maintainers/phptek)

---

Top Contributors

[![phptek](https://avatars.githubusercontent.com/u/478440?v=4)](https://github.com/phptek "phptek (97 commits)")[![jakxnz](https://avatars.githubusercontent.com/u/1634995?v=4)](https://github.com/jakxnz "jakxnz (1 commits)")

---

Tags

jsonjsonpathmultivaluesilverstripejsonjsonpathpostgressilverstripequerytextmultidbfieldmultivaluemultivaluefield

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phptek-jsontext/health.svg)

```
[![Health](https://phpackages.com/badges/phptek-jsontext/health.svg)](https://phpackages.com/packages/phptek-jsontext)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[nahid/jsonq

JsonQ is a PHP based json data query library

873651.3k7](/packages/nahid-jsonq)[galbar/jsonpath

JSONPath implementation for querying and updating JSON objects

2136.4M78](/packages/galbar-jsonpath)[unclecheese/silverstripe-serialised-dbfields

Provides serialised data (YAML, JSON) in text fields that are traverseable as nested ViewableData objects.

106.2k](/packages/unclecheese-silverstripe-serialised-dbfields)[remorhaz/php-json-path

JSONPath implementation in PHP

15155.5k1](/packages/remorhaz-php-json-path)[estahn/json-query-wrapper

Wrapper for jq, a lightweight and flexible command-line JSON processor

1548.7k1](/packages/estahn-json-query-wrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
