-
Notifications
You must be signed in to change notification settings - Fork 154
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
query: potential candidate for query format: jsonpath #2924
Comments
If I'm building an API around the new QUERY method, surely I'd have to specify the media types for both query and response, right? So I'm not sure what's special about JSONPath. |
The theory is that for a media type to be applicable for QUERY the semantics for QUERY should be specified somewhere. That idea dates back to the time when people just used application/json as payload format for PATCH, with different ideas what that actually means. But I agree that the semantics for JsonPath with QUERY are pretty clear, maybe except for the question what the JSON document being queried actually is. But that can remain an implementation detail of the server. Any recommendations about what format we should use in the response? Maybe you even could suggest an example? |
I disagree at a basic level. A JSONPath selects the parts of some JSON
text that it matches. What the JSON text is, and what the effect of
selecting parts of it is, seem entirely application-dependent. Maybe it’s
applied to the user’s order history and forwards the selected portions to
Accounting, and returns status code 200 but no body. Maybe it applies the
JSONPath to that same order history, creates an analysis, and returns
application/csv. These things are designed to be general-purpose
expressions and I really can’t think of anything useful that could be said.
-T
…On Oct 20, 2024 at 9:55:06 AM, Julian Reschke ***@***.***> wrote:
The theory is that for a media type to be applicable for QUERY the
semantics for QUERY should be specified somewhere. That idea dates back to
the time when people just used application/json as payload format for
PATCH, with different ideas what that actually means.
But I agree that the semantics for JsonPath with QUERY are pretty clear,
maybe except for the question what the JSON document being queried actually
is. But that can remain an implementation detail of the server. Any
recommendations about what format we should use in the response? Maybe you
even could suggest an example?
—
Reply to this email directly, view it on GitHub
<#2924 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEJEZHO73S3LG3L5MQYVLZ4PN6VAVCNFSM6AAAAABQINSZYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRVGEYTOMJWHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Ok, just checking: we don't want to define a standard response format, because we want to leave it specific to the server? I agree with that. But for an example, would you recommend a specific response format (iff that this is just an example)? |
That example of sending a JSONPath which is applied to the user's saved
data and returns an analysis in a CSV isn't terrible? Or it might return a
nice graph as a JPEG or PDF.
…On Sun, Oct 20, 2024, 12:34 PM Julian Reschke ***@***.***> wrote:
Ok, just checking: we don't want to define a standard response format,
because we want to leave it specific to the server? I agree with that.
But for an example, would you recommend a specific response format (iff
that this is just an example)?
—
Reply to this email directly, view it on GitHub
<#2924 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEJEZ3XJOF74XEEAEY7ADZ4QAULAVCNFSM6AAAAABQINSZYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRVGE4DSMZXGU>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I think the difference here is that PATCH has side effects on the resource, whereas QUERY should not (generally). PATCH needed definition to describe those side effects, so it doesn't become another POST escape hatch. |
Ok, so we'll just add an example using jsonpath. |
Proposal:
from a fictious RFC errata database, selects all errata for RFC9110 which have not been rejected, and returns id, submission_date for each
|
On Nov 1, 2024 at 1:34:45 PM, Julian Reschke ***@***.***> wrote:
Content-Type: example/query
Accept: application/jsonpath
That should be Content-Type: application/jsonpath, Accept:
application/json, no?
Proposal:
…
QUERY /errata.json HTTP/1.1
Host: example.org
Content-Type: example/query
Accept: application/jsonpath
***@***.***=="RFC9110" && @errata_status_code!="Rejected"].[errata_id, submit_date]
from a fictious RFC errata database, selects all errata for RFC9110 which
have not been rejected, and returns id, submission_date for each
HTTP/1.1 200 OK
Content-Type: application/json
[
"7105",
"2022-08-26",
"7109",
"2022-08-31",
"7138",
"2022-09-23",
"7306",
"2023-01-13",
"7419",
"2023-04-11"
]
—
Reply to this email directly, view it on GitHub
<#2924 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEJE5DR5WYV4B73HCY3PDZ6PQWLAVCNFSM6AAAAABQINSZYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJSGU2TCMZQGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Oh, indeed. Thanks for catching this. Will edit in place. |
We could also use this as example of conneg:
|
Part of #1906 |
I agree with using Accept: to specify the desired response format (we could even give application/json a specific meaning in this context); application/jsonpath is fine as a query content type. |
@timbray @cabo - I need help with getting the syntax correct. What tool should I use? Is https://jsonpath.com/ ok? FWIW, the sample data is https://www.rfc-editor.org/errata.json |
-> #1906 |
I use a simple tool called jpt (gem install jpt). @glyn probably has more recommendations... |
jpt seems to use the same parser as https://jsonpath.com/... I should have been more precise on what problems I encountered: Escaping "-" in names. The query
results in parse error:
The other question was how to specify multiple members for output; in the original example I had:
Is this even possible in regular JSONPath? |
Here's what I found works if I altered their example: That is, if you want "-", you have to not use the |
@["doc-id"] is a way to include other characters in a name.
We didn't include projection (the SELECT... part of SQL) in JSONPath. |
I now have
Do you have a good idea how to produce JSONPath results for the response body? Is there a notation I could use? A list of normalized paths perhaps? |
JSONPath does not specify an output format, just saying that this could be a list of normalized paths and/or the values at these paths. The reply at line 896 looks good to me as an example for representing the latter list as a JSON array. Please do fix line 884 ["doc\u002did"]; I have no idea what made Martin escape the hyphen-minus, which is perfectly valid ASCII at this point. |
Please try. "doc-id" is not accepted by the parser: #2924 (comment) For the query, I wanted to indent it in order to avoid overflowing the rfc txt limits. If you can suggest a better variant, please go ahead. |
hyphen-minus is not a name-char, so a member-name-shorthand like
is a syntax error, as is
Instead,
or
is the correct way to use this member name in a name-segment. |
That's why I was so confused. Let me try again. Indeed:
does work. I believe I tried
Sorry for the confusion |
Sorry for the slow reply. Here are two "live" implementations of RFC 9535 which you may already have gotten from my blog post: |
See #3002 |
@glyn - thanks; I just merged the new examples section. Maybe you want to check? |
Confirmed that this is valid JSONPath syntax. |
Spec: https://www.rfc-editor.org/rfc/rfc9535.html
The text was updated successfully, but these errors were encountered: