承接 loilo/jsonpath 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

loilo/jsonpath

Composer 安装命令:

composer require loilo/jsonpath

包简介

Runs RFC9535 compatible JSONPath queries against a data set

README 文档

README

The jsonpath-php logo: an LED matrix panel displaying the characters "{ $ }" as glowing yellow dots

jsonpath-php

An implementation of RFC 9535 JSONPath

Tests Packagist PHP Version

This is a PHP implementation of JSONPath, a query language for JSON. It aims for 100% compatibilty with the JSONPath syntax standardized in RFC 9535.

Currently, this library passes 99% of the work-in-progress JSONPath Compliance Test Suite (with the test suite version on Feb 21, 2025). All of the the missing 1% are UTF-16 related tests, which should not affect most day-to-day users (and which I'm not sure how to implement in PHP — any help is appreciated!)

Installation

composer require loilo/jsonpath

Note that at least PHP 8.0 is needed to use jsonpath-php. For technical reasons, unit tests are only run against PHP 8.2+.

Usage

use Loilo\JsonPath\JsonPath;

$query = new JsonPath('$.users[*].name');

$result = $query->find([
	'users' => [
		[ 'name' => 'John Doe' ],
		[ 'name' => 'Jane Doe' ],
	],
]);

print_r($result);

/*
Prints:

Array
(
	[0] => John Doe
	[1] => Jane Doe
)
*/

$path_result = $query->paths([
	'users' => [
		[ 'name' => 'John Doe' ],
		[ 'name' => 'Jane Doe' ],
	],
]);

print_r($path_result);

/*
Prints:

Array
(
	[0] => Loilo\JsonPath\PathResult Object
		(
			[value] => John Doe
			[path] => $['users'][0]['name']
		)

	[1] => Loilo\JsonPath\PathResult Object
		(
			[value] => Jane Doe
			[path] => $['users'][1]['name']
		)
)
*/


$path_segments_result = $query->path_segments([
	'users' => [
		[ 'name' => 'John Doe' ],
		[ 'name' => 'Jane Doe' ],
	],
]);

print_r($path_segments_result);

/*
Prints:

Array
(
	[0] => Loilo\JsonPath\PathSegmentsResult Object
		(
			[value] => John Doe
			[segments] => Array
				(
					[0] => users
					[1] => 0
					[2] => name
				)
		)

	[1] => Loilo\JsonPath\PathSegmentsResult Object
		(
			[value] => Jane Doe
			[segments] => Array
				(
					[0] => users
					[1] => 1
					[2] => name
				)
		)
)
*/

Development

Project Scope

Please note that I'm striving for feature parity with the jsonpath-js library and therefore will add neither features nor fixes to the search logic that are not reflected in jsonpath-js itself.

If you have any issues with the library that are not obviously bugs in this PHP port, and you happen to know JavaScript, please check if your use case works correctly in the online demo of jsonpath-js since that's the canonical implementation. If the issue appears there as well, please open an issue in their repo.

Setup

To start development on jsonpath-php, you need git, PHP (≥ 8.2), Composer and npm.

Since code is formatted using Prettier, it's also recommended to use an editor which supports Prettier formatting.

Clone the repository and cd into it:

git clone https://github.com/loilo/jsonpath-php.git
cd jsonpath-php

Install Composer dependencies:

composer install

Install npm dependencies. They are needed for code formatting and for compiling the Peggy grammar.

npm ci

Formatting the Code

The code is formatted using Prettier. To format the code, run:

npm run format

Compiling the Grammar

The JSONPath grammar is defined in src/grammar/rfc9535-parser.pegjs. To compile it to src/PeggyParser.php, run:

npm run generate-parser

Quality Assurance

There are different kinds of code checks in place for this project. All of these are run when a pull request is submitted but can also be run locally:

Command Purpose Description
vendor/bin/phpcs check code style Run PHP_CodeSniffer to verify that the source code abides by the PSR-12 coding style.
vendor/bin/phpstan static analysis Run PHPStan against the codebase to avoid type-related errors and unsafe coding patterns.
vendor/bin/pest check program logic Run all Pest tests from the tests folder.

Credit

All the credit goes to the creator of jsonpath-js. They did all the hard conceptual work, this PHP library is merely a port of their code.

loilo/jsonpath 适用场景与选型建议

loilo/jsonpath 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.74k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 loilo/jsonpath 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 loilo/jsonpath 我们能提供哪些服务?
定制开发 / 二次开发

基于 loilo/jsonpath 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-19