Closed drasier closed 2 years ago
Hi, it seems you hit a bug. Despite tests covering this functionality, this particular use case was not tested. I've added your example as a test case and it is indeed failing https://app.travis-ci.com/github/halaxa/json-machine/jobs/540576779#L317. I'll try to fix it asap. You can too ;)
Awesome (for finding a bug, not for the issue itself haha)
I can try but, honestly, I'm not a pro developer and I might cause more trouble than help... :S In fact, I've browsed the code and I found it very overwhelming..
For now I've found a workarround using a classic foreach instead of your awesome tool. But please let me know if this gets fixed. I'd love to use json-machine as the performance is incredible. Congrats on that btw.
Best, Jose Sobre 30/09/2021 17:02:08, Filip Halaxa @.***> escribió: Hi, it seems you hit a bug. Despite tests covering this functionality, this particular use case was not tested. I've added your example as a test case and it is indeed failing https://app.travis-ci.com/github/halaxa/json-machine/jobs/540576779#L317 [https://app.travis-ci.com/github/halaxa/json-machine/jobs/540576779#L317]. I'll try to fix it asap. You can too ;) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub [https://github.com/halaxa/json-machine/pull/62#issuecomment-931403890], or unsubscribe [https://github.com/notifications/unsubscribe-auth/ABSIPWPDOFA7MEDND6ZYEF3UER3W7ANCNFSM5FAVEP2A]. Triage notifications on the go with GitHub Mobile for iOS [https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675] or Android [https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub].
Hi, so I've just updated the tests because the problem with my failing test case 4787786 was the bad handling of keys in the tests, not the code. So this case is passing now - which means that your code should too. I've not changed the parser code. Are you sure you're using the most current version of JSON Machine?
To install this particular branch via composer to test it out, use dev-issue-62
as a version constraint.
Hi, I've got the same problem got a very deep levelled json and I'm trying to access them all by using the subtree and '-' wildcard.
{ PublicationNodes: [ {Description: { Value: { nl: "random1", fr: 'random1' }}, {Description: { Value: { nl: "random2", fr: 'random2' } }}, {Description: { Value: { nl: "random3", fr: 'random3' } }} ] }
But whenever I use:
$data = JsonMachine::fromFile(BASE_PATH.'/files/file.json', "/PublicationNodes/-/Description", new ExtJsonDecoder()); foreach ($data as $key => $value) { print_r($key); print_r($value); }
It will only show the first one:
stdClass Object ( [fr] => random1 [nl] => random1 )
I've just tried it on a json like this example, and it works, so appareantly it doesn't work on big json files? That seems to be the issue, I've stripped down the big file to having the same structure but without any subtrees and it works, for now it looks like it just skips stuff, because right now with the big file the results are shown in in instant, so it looks like its not even looping through it.
Would it be possible to provide some anonymized version of a minimal, deep leveled file which it crashes on?
b7d6a81 fixes failing build.
@arienvanhelden After fixing your example JSON everything works. You missed one }
:
{
"PublicationNodes": [
{
"Description": {
"Value": {
"nl": "random1",
"fr": "random1"
}
} <- missing brace in your example
},
{
"Description": {
"Value": {
"nl": "random2",
"fr": "random2"
}
}
},
{
"Description": {
"Value": {
"nl": "random3",
"fr": "random3"
}
}
}
]
}
I'm closing it for now. Feel free to comment with a failing example.
json example:
[ {"id":125}, {"id":785}, {"id":459}, {"id":853} ]
php code:
$items = JsonMachine::fromFile( dirname(__FILE__) . '/data/products.json', '/-/id');
foreach ($items as $data) { echo $data; }
output:
125
What I'm doing wrong? JSON pointers '/0/id', '/1/id', '/2/id', etc work great. But I can't seem to get the '-' wildcard working...