How to get specific fields from nested json
ryhill opened this issue · comments
Hi,
How to fetch specific fields from nested json
Thanks
KIRAN
use select
method like this
$jq->from('products')
->select('name', 'price')
->where('cat', '=', 2)
->get();
Select isn't working..The error thrown is
Fatal error: Call to undefined method Jsonq::select() in __________
which version are you using?
It's worked for me and I use the jsonq
version is v5.1.2
. Here is the following sample code:
And the data.json
is available in this package README.md
.
<?php
require_once 'vendor/autoload.php';
use Nahid\JsonQ\Jsonq;
$jq = new Jsonq('data.json');
$res = $jq->from('products')
->select('name', 'price')
->where('cat', '=', 2)
->get();
var_dump($res);