PHPackages                             eftec/services\_json - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. eftec/services\_json

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eftec/services\_json
====================

PHP implementaion of json\_encode/decode

2.5(1y ago)531.2k↓30.9%1BSD-2-ClausePHPPHP &gt;=7.4

Since Nov 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/EFTEC/Services_JSON)[ Packagist](https://packagist.org/packages/eftec/services_json)[ RSS](/packages/eftec-services-json/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

Services\_JSON
==============

[](#services_json)

PHP implementation of json\_encode/decode for PHP 7.2 and higher. This library works with and without quoted keys.

[![Packagist](https://camo.githubusercontent.com/58191c561b7fde08dee90f632b53c27bb04ff47c733a49943457f21f4a0f43ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65667465632f73657276696365735f6a736f6e2e737667)](https://packagist.org/packages/eftec/services_json)[![Total Downloads](https://camo.githubusercontent.com/a89a577605188c01cb78a9778fba1862598e8f9fbac07fe2a07b0ed7df21f791/68747470733a2f2f706f7365722e707567782e6f72672f65667465632f73657276696365735f6a736f6e2f646f776e6c6f616473)](https://packagist.org/packages/eftec/services_json)![Maintenance](https://camo.githubusercontent.com/921e6ae18860631d0290081633bc3fec5d982aaa7cbcaa185e7d1bd46d6c08d5/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032322e737667)![composer](https://camo.githubusercontent.com/08623182d7b037246f11c0ad4aec3fe405dcf9d668058398497abd1a9a770e9d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d253345312e362d626c75652e737667)![php](https://camo.githubusercontent.com/0d20998129714e2662748003f3e0fab165e7f10d9dd4eb097376217b12c07b15/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e782d677265656e2e737667)![php](https://camo.githubusercontent.com/c8563252142a1b6b18a7d6bcbbbb93f8d6d5c975876bb5b5a2d5fa176292d955/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e782d677265656e2e737667)![CocoaPods](https://camo.githubusercontent.com/347353606ed8f26b45bcf9da083db0063fa1dadd1baef36a5f3bf9ce1d127548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d37302532352d79656c6c6f772e737667)

This package provides a simple encoder and decoder for JSON notation. It is intended for use with client-side Javascript applications that make use of HTTPRequest to perform server communication functions - data can be encoded into JSON notation for use in a client-side javascript, or decoded from incoming Javascript requests. JSON format is native to Javascript, and can be directly eval() with no further parsing overhead.

So, what is the goal with this version?
---------------------------------------

[](#so-what-is-the-goal-with-this-version)

While this version doesn't have a better performance than **json\_encode()** and **json\_decode()** available as extension, but it has the next features:

- it doesn't require an extension. If you can't install ext-json, then you can use this version.
- **it works with JSON with unquoted keys** (for example JavaScript notation), {aaa:2,bbb:"hello"}
- **it could also work with unquoted values** {"aaa":2,"bbb":hello}
- **it could also work with unwrapped content** "aaa":2,"bbb":"hello" instead of {aaa:2,bbb:"hello"}
- It is a simple .php file with no dependency.

Usage
-----

[](#usage)

### Getting started using composer

[](#getting-started-using-composer)

1. Install the library using composer

```
composer require eftec/services_json
```

2. Include the dependency

```
use eftec\ServicesJson\Services_JSON;
include '../vendor/autoload.php';
```

See the folder examples for further examples

### Getting started without composer

[](#getting-started-without-composer)

1. Copy this file: [Services\_JSON/Services\_JSON.php](https://github.com/EFTEC/Services_JSON/blob/main/src/Services_JSON.php)
2. Include the file

    ```
    use eftec\ServicesJson\Services_JSON;
    include 'Services_JSON.php'; // or where is located the file.
    ```

### Decode

[](#decode)

Decode a JSON string into a stdclass or an associative array

```
$json='{"hello":{"a":2,"b":3},"world":[1,2,3,"aaa"]}';
var_dump(Services_JSON::decode($json)); // as stdclass
var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY)); // as array
```

It also works with unquoted keys

```
$json='{hello:{a:2,b:3},world:[1,2,3,"aaa","bbbb"]}';  // the keys are unquoted.
var_dump(Services_JSON::decode($json)); // as stdclass
var_dump(Services_JSON::decode($json,Services_JSON::GET_ARRAY)); // as array
```

#### Json unwrapped.

[](#json-unwrapped)

With the flag **Services\_JSON::DECODE\_FIX\_ROOT**, it also works when the origin text misses \[\] and {} at the start of the code. Note, this feature is not foolproof, for example "\[1,2,3\],\[4,5,6\]" will not wrap as "\[\[1,2,3\],\[4,5,6\]\]"

```
{"a":222,"b:"ccc"}  # normal json
"a":222,"b:"ccc"    # json without the root parenthesis.

```

```
Services_JSON::decode('1,2,3',Services_JSON::GET_ARRAY | Services_JSON::DECODE_FIX_ROOT); // returns [1,2,3]
Services_JSON::decode('"k1":"v1", k2:2',Services_JSON::GET_ARRAY | Services_JSON::DECODE_FIX_ROOT) // returns [ 'k1' => 'v1','k2'=>2]
```

> Note: DECODE\_FIX\_ROOT flag detects if the near character is ":" or ",". If the closest character is ":", then it returns an object, otherwise it returns a list. If there is none, then it returns a list.

#### Json with unquoted values

[](#json-with-unquoted-values)

With the flag **Services\_JSON::DECODE\_NO\_QUOTE** it also works when the string values are not quoted.

> Note: invisible characters at the beginner and at the end (tabs, line carriages) will be trimmed.

```
Services_JSON::decode('{"a":aaa,"b":bbbb,"c": aaaaa}'
  , Services_JSON::GET_ARRAY | Services_JSON::DECODE_NO_QUOTE) // ['a'=>'aaa','b'=>'bbbb','c' => 'aaaaa']
```

### Encode

[](#encode)

Encode transform a value (array, object, primitive value, etc.) into a json expression (a string)

```
$array=["hello"=>['a'=>2,'b'=>3],'world'=>[1,2,3,"aaa","bbb"]];
$obj=(object)$array;
var_dump(Services_JSON::encode($array));  // encode an associative array
var_dump(Services_JSON::encode($obj)); // encode an object
```

Changelog
---------

[](#changelog)

- 2.5
    - now allows "@" and "." for key values.
- 2.4
    - update requirements to php 7.4
    - added more type hinting (type validation)
- 2.3.2
    - Added flag to decode() DECODE\_NO\_QUOTE
- 2.3.1
    - deleted unused code
    - fixed comments.
    - 25% of the code has been refactored.
- 2.3
    - Fixed a typo with a comment.
    - added phpunit. The entire code is tested but special codification.
- 2.2
    - Now the library is static, so you can call the methods without creating an instance.
    - If you want to work with the non-static library, then install 1.1
- 1.1
    - It works with PHP 7.2 and higher (including PHP 8.0 and 8.1)
    - It doesn't require PECL to work.
    - The code was cleaned
    - Web header is removed.
    - Method decode() could return an associative array.
- 1.0.3-1.0.0 PECL version. It only works with PHP 4.x and PHP 5.x

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance41

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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 ~141 days

Recently: every ~211 days

Total

7

Last Release

488d ago

Major Versions

1.1 → 2.22022-11-07

PHP version history (2 changes)1.1PHP &gt;=7.2.5

2.4PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bf6ba9d7f6f6c3ecde2779a29e1a4948f0f338c074ddceb3fbeb79c6dd1e68c?d=identicon)[JorgeCastro](/maintainers/JorgeCastro)

---

Top Contributors

[![jorgecc-business-account](https://avatars.githubusercontent.com/u/12418702?v=4)](https://github.com/jorgecc-business-account "jorgecc-business-account (13 commits)")[![jorgecc](https://avatars.githubusercontent.com/u/9570242?v=4)](https://github.com/jorgecc "jorgecc (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eftec-services-json/health.svg)

```
[![Health](https://phpackages.com/badges/eftec-services-json/health.svg)](https://phpackages.com/packages/eftec-services-json)
```

PHPackages © 2026

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