在 PHP 中以声明的方式指定如何从 JSON 文档中提取元素
mtdowling/jmespath.php 包进行安装。$result = JmesPath\search($expression, $data);
// or, if you require PSR-4 compliance.
$result = JmesPath\Env::search($expression, $data);jmespath.php 使用 运行时。目前有两个运行时: AstRuntime
以及 CompilerRuntime。
JmesPath\search() 和 JmesPath\Env::search() 使用了 AstRuntime
默认。
AstRuntime 会解析表达式,将结果的 AST 缓存到内存中,并 使用外部树访问器解释 AST。AstRuntime 提供了一个很好的 用于解释具有低级别 JMESPath 表达式的一般方法 中等程度的重复利用。
$runtime = new JmesPath\AstRuntime();
$runtime('foo.bar', ['foo' => ['bar' => 'baz']]);
// > 'baz'JmesPath\CompilerRuntime 为那些 JMESPath 表达式重用程度中等到高的应用程序提供了最佳性能。 CompilerRuntime 会遍历 JMESPath AST 并生成 PHP 源代码,从而使速度提高 7 倍到 60 倍。
暂无开放 Issues,或尚未同步最近议题。