ietf-wg-jsonpath / draft-ietf-jsonpath-base

Development of a JSONPath internet draft
https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/
Other
59 stars 20 forks source link

Behaviour for invalid JSON #229

Closed glyn closed 2 years ago

glyn commented 2 years ago

@timbray wrote:

Hmm, I don't see anything in the draft spec about what happens if you try to apply a JSONPath and what you're trying to apply it to is broken, i.e. not valid JSON. Maybe we're in a world where callers have to live with failed applications anyhow?

glyn commented 2 years ago

It depends. For example, the APIs of some JSONPath implementations take a rich type which represents a valid JSON value. In that case, handling invalid JSON happens before the API is called and is not a concern of the API. But other implementations could have an API which takes a string, which may or may not represent valid JSON.

So, to be clear, we probably need some words in the spec which says the spec does not prescribe how invalid JSON is handled. This is better than silence.

Or we could require that invalid JSON cannot result in a non-empty nodelist from a JSONPath query.

danielaparker commented 2 years ago

@timbray

I don't see anything in the draft spec about what happens if you try to apply a JSONPath and what you're trying to apply it to is broken

But "brokenness" would apply to JSON texts, wouldn't it? As @cabo noted in (https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base/pull/223#issuecomment-1184361289), "JSON text is a sequence of characters, an unparsed piece of JSON for interchange, with newlines and backslashes and all that. JSONPath never looks at JSON texts. JSON value is the RFC 8259 term for what JSONPath looks at."

The parser would care about "broken" JSON texts, but JSONPath should never see them.

timbray commented 2 years ago

Agree with last two points. The spec describes the application of a JSONPath expression to parsed JSON, so JSON texts are out-of-scope. As @glyn says, we should make that explicit.

gregsdennis commented 2 years ago

JSON Schema simply defines that it operates on the JSON data model.

JSON Schema interprets documents according to a data model.

This section covers a range of issues that we've found in our history, including handling whitespace differences, duplicate keys, etc.

I think this is a great approach.