New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document-dependent path evaluation #102
Comments
TL;DR Just omit the dash at the end. Hi. Your example works as expected. It seems in your case the JSON Pointer ( |
Thanks for the quick response! You're right. I tried to reduce the case and did it incorrectly. Let me try again: Let's say we have a function cells($matrix) {
foreach ($matrix as $row) {
foreach ($row as $cell) {
yield $cell;
}
}
} $options = ['pointer' => '/table/-'];
Items::fromString('{"table": [[1,2], [3,4]]}', $options);
// Expected: [1,2,3,4]
// Actual: same
Items::fromString('{"table": [[1,2], 3]}', $options);
// Expected: error
// Actual: [1,2,3] Is this possible? |
And the reason I was using
|
What are your thoughts on an option
All of them return a single item, except |
I'm not sure what the question is now. Can you be more specific? Anyway, let me just elaborate a little on the Try this and you'll see no deep flattening is happening: $options = ['pointer' => '/table/-'];
Items::fromString('{"table": [[[1,2]], [3,4]]}', $options);
// Expected: [[1,2],3,4] Also, this example is not expected to produce an error: $options = ['pointer' => '/table/-'];
Items::fromString('{"table": [[1,2], 3]}', $options); because at |
I would expect a behavior where:
Currently, even a non-wildcard component explodes the items (but has nowhere to indicate this in the path), if the element pointed to is an object/array. It is this behavior that I would like to have a way to disable. Below is (yet another) example, which demonstrates both my concerns (indexes in Say you have two-level array
The following is not valid, because it's not really
I would like to
This cannot be currently achieved:
|
|
Sorry for being brief ;) |
No worries, I appreciate your responses, responsiveness, and patience with me iterating on trying to get the best example.
Yes, I understand. But disabling this feature is essentially my feature request! :D
I'm not saying that the items do not get iterated over, just that in the
By "silently ignored" I don't mean not returned by the iterator (that's what happens with Perhaps I owe an explanation for this admittedly weird use-case: I'm querying OpenAI's text completions AI with the new function calling/structured output mechanism, which returns JSON. JSON Machine is used to return results in a streaming fashion to the user live (see videos here if curious). That table should be In recap, I don't think path nr# 2 ( |
Now it makes perfect sense 😁. Because in terms of JSON Machine, there's no 'flattening', I'd suggest modifying the scalar parsing logic, which is what's actually behind your problem. Maybe an option something like
This example of yours:
would then throw an error with option |
Also for a less predictable structure maybe #36 would help? |
Let's say we have a property with an array of dynamically-typed, user-provided parameters.
This makes JSON Machine not very useful for working with documents with a more dynamic schema. Moreover, even arrays have a special case at length == 0.
I checked the JSON Pointer spec to see if this is an implementation bug or by design. Seems like JSON Pointer is not intended for the (JSONPath-like) selection at all, but for navigation to a single node. Even the
-
is interpreted differently (the (nonexistent) member after the last array element
vsa wildcard which matches any array index
). It also would not have the above problem and would always navigate to the expected subtree. It would be better if the readme said "a syntax inspired by JSON Pointer".Re. a solution, it would be great if there was an option to not automatically descend deeper than the specified path and make the subtree selection not dependent on the values in it.
The text was updated successfully, but these errors were encountered: