PHPackages                             eboubaker/json-finder - 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. eboubaker/json-finder

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

eboubaker/json-finder
=====================

a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

v1.2.0(4y ago)33.8k↓50%MITPHPPHP &gt;=7.4

Since Apr 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Eboubaker/JSONFinder)[ Packagist](https://packagist.org/packages/eboubaker/json-finder)[ RSS](/packages/eboubaker-json-finder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (12)Used By (0)

JSONFinder
==========

[](#jsonfinder)

a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

[![Latest Stable Version](https://camo.githubusercontent.com/0040c218283884e8b590e513e241c1dea6e241d2935acbcf08ae67f37dfaa95c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65626f7562616b65722f6a736f6e2d66696e6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eboubaker/json-finder)[![PHP Version Require](https://camo.githubusercontent.com/c822c2a127df46271669f22f4fe612d2d8d29a1393b4791e8246b573273596cd/687474703a2f2f706f7365722e707567782e6f72672f65626f7562616b65722f6a736f6e2d66696e6465722f726571756972652f706870)](https://packagist.org/packages/eboubaker/json-finder)[![CI Status](https://github.com/eboubaker/JSONFinder/actions/workflows/CI.yml/badge.svg)](https://github.com/Eboubaker/JSONFinder/actions)[![Tests Coverage](https://github.com/Eboubaker/JSONFinder/raw/main/coverage_badge.svg)](https://github.com/Eboubaker/JSONFinder/actions)

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

[](#installation)

install the library with composer

```
composer require eboubaker/json-finder

```

Quick Start
-----------

[](#quick-start)

suppose you want to scrap all json from an http response (from &lt;script&gt; tags).

```
use Eboubaker\JSON\JSONFinder;

$html = file_get_contents('http://www.youtube.com');
$finder = JSONFinder::make();

/**
 * @var \Eboubaker\JSON\JSONArray $foundEntries
 */
$foundEntries = $finder->findEntries($html);

// associative array of all found json entries
$associative = $foundEntries->assoc();

// 4th entry in the JSONArray
$entry = $foundEntries[3];

// get json string of the first entry (similar to json_encode)
$jsonString = strval($entry);

// loop through entries of the JSONArray ($foundEntries)
foreach($foundEntries as $key => $value) {
    // ....
}

// loop through every deeply nested value(not object or array)
foreach($foundEntries->values() as $keyPath => $value) {
    // ....
}

// pretty print the json entry with indentation of 2 spaces
echo $foundEntries->toReadableString(2);
```

### Value Encoding

[](#value-encoding)

you can encode php values into json string without ext-json.

```
use Eboubaker\JSON\JSONObject;

$phpvalue = [
    "a" => "b",
    "e" => [
        "f" => null,
        "h" => [
            "i" => "j",
            "k" => [1, 2, 3e-13, ["x"=> 0.3]]
        ]
    ]
];
$obj = JSONObject::from($phpvalue);
echo strval($obj);// '{"a":"b","e":{"f":null,"h":{"i":"j","k":[1,2,3.0E-13,{"x":0.3}]}}}'
```

### JSON Query

[](#json-query)

you can search for values inside the json tree. with dot notation path and wildcards "`*`" "`**`".

PathMeaning`video.formats.*`every entry inside `video.formats` (3 results)`video.**`Every deeply nested value inside `video` ("12345","mp4","https://example.com/video720.mp4",..., "1280x720") (10 results)`video.**.url`Every deeply nested value inside `video` with key `url` ("https://example.com/video720.mp4",...) (3 results)---

```
use Eboubaker\JSON\JSONObject;

$obj = JSONObject::from([
    "meta" => [
        "id" => "12345",
        "title" => "My Title",
    ],
    "video" => [
        "id" => "12345",
        "formats" => [
            [
                "name" => "mp4",
                "url" => "https://example.com/video720.mp4",
                "resolution" => "1280x720",
            ],
            [
                "name" => "mp4",
                "url" => "https://example.com/video1080.mp4",
                "resolution" => "1920x1080",
            ],
            [
                "name" => "webm",
                "url" => "https://example.com/video720.webm",
                "resolution" => "1280x720",
            ],
        ]
    ]
]);

$obj->getAll('formats'); // empty array [], $obj does not contain 'formats' path

$result = $obj->getAll('meta.id'); // [0 => JSONValue("12345")]
$video_id = $result[0];

// get all deep entries that contains an 'id' key
$has_id = $obj->getAll('**.id');

// get all formats in 'video.formats' path
$all_formats = $obj->getAll('video.formats.*');

// you can apply a filter to the results
$mp4_formats = $obj->getAll('video.formats.*', fn($v) => $v->get('name')->equals('mp4')); // ['video.formats.0' => JSONObject({"name":"mp4","url":"https://example.com/video720.mp4","resolution":"1280x720"})]

// return paths of found results as the keys in the result array
$has_id = $obj->getAll('**.id', null, true); // ['meta.id' => JSONValue("12345"), 'video.id' => JSONValue("12345")]
```

### Find JSON object/array

[](#find-json-objectarray)

You can find a single json object/array which contains specific keys using `JSONObject::search()`or `JSONArray::search()`.
the method accept a list of paths with optional value filter.
will returns the target that contains all the provided paths.

```
use Eboubaker\JSON\JSONObject;
use Eboubaker\JSON\Contracts\JSONEntry;

$object = JSONObject::from([
    "response" => [
        "hash" => "a5339be0849ced1ffe",
        "posts" => [
            [
                "id" => "1634",
                "likes" => 700,
                "text" => "Machine learning for beginners",
            ],
            [
                "id" => "1234",
                "likes" => 200,
                "text" => "top 10 best movies of 2019",
                "comments" => [
                    [
                        "id" => "1134",
                        "likes" => 2,
                        "replies" => [],
                        "content" => "thanks for sharing",
                    ],
                    [
                        "id" => "1334",
                        "content" => "this video is bad",
                        "likes" => 0,
                        "replies" => [
                            [
                                "id" => "1435",
                                "likes" => 0,
                                "content" => "this is not true",
                            ],
                            [
                                "id" => "1475",
                                "likes" => 0,
                                "content" => "agree this is the worst",
                            ]
                        ],
                    ]
                ],
            ]
        ]
    ]
]);

// get first object which matches these paths and filters.
$comment_with_likes = $object->search([
    "content",
    "likes" => fn(JSONEntry $v) => $v->value() > 0
]);
echo $comment_with_likes;// {"id":"1134","likes":2,"replies":[],"content":"thanks for sharing"}

$post_with_comment_replies = $object->search([
    "comments.*.replies"
]);
echo $post_with_comment_replies['id'];// "1234"

// more than 0 replies
$comment_with_replies = $object->search([
    "replies.*"
]);
echo $comment_with_replies['id'];// "1334"

$comment_with_bad_words = $object->search([
    "content" => fn(JSONEntry $v) => $v->matches('/worst|bad/')
]);

echo $comment_with_bad_words['id'];// "1334"
```

### Controlling results of JSONFinder

[](#controlling-results-of-jsonfinder)

you can add flags to the JSONFinder factory to set the allowed types of values that the JSONFinder will return.
for example if you want to also include javascript objects in the resutls you can add the T\_JS flag. this will also match javascript object-keys or javascript strings that are quoted with single quote `'`

```
use Eboubaker\JSON\JSONFinder;

// this finder can also find javascript objects/arrays
$finder = JSONFinder::make(JSONFinder::T_ALL_JSON | JSONFinder::T_JS);
$finder->findEntries("let data = {jskey: 1};")->first();// JSONObject({"jskey":1})
$finder->findEntries("var x = Object.freez({'js-key': 'js string'})")->first();// JSONObject({"js-key":"js string"})
```

All other functions are self documented with PHPDoc.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.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 ~1 days

Total

11

Last Release

1488d ago

Major Versions

v0.2.4 → v1.0.02022-04-13

PHP version history (2 changes)v0.1.0PHP ^7.4|^8.0|^8.1

v0.2.4PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b5306629ec9df026c8fb7fbfbe3ee0b1f93f7249358fd77be82859d03aa0040?d=identicon)[eboubakkar](/maintainers/eboubakkar)

---

Top Contributors

[![Eboubaker](https://avatars.githubusercontent.com/u/37766821?v=4)](https://github.com/Eboubaker "Eboubaker (137 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

jsonphpscraping

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eboubaker-json-finder/health.svg)

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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