-
Notifications
You must be signed in to change notification settings - Fork 0
Rough draft #1
base: main
Are you sure you want to change the base?
Rough draft #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,109 @@ | ||||||||||
# JSONPath axiomatic semantics | ||||||||||
|
||||||||||
** WORK IN PROGRESS ** | ||||||||||
|
||||||||||
## sequences of JSON values | ||||||||||
|
||||||||||
A JSONPath is modelled as mapping one sequence of JSON values to another sequence of JSON values. | ||||||||||
The `<>` notation is used for sequences, to try to distinguish these from JSON arrays. | ||||||||||
|
||||||||||
Empty sequence: `<>`. | ||||||||||
|
||||||||||
Concatenation: `<a, b> = <a> ^ <b>`. | ||||||||||
|
||||||||||
So, for example, the sequence `<a, b, c>` is equivalent to the concatenation of three single item | ||||||||||
sequences `<a> ^ <b> ^ <c>`. | ||||||||||
|
||||||||||
## sequence semantics | ||||||||||
A selector `s` takes a sequence of values and applies to each one separately. | ||||||||||
The results are then concatenated. | ||||||||||
|
||||||||||
``` | ||||||||||
<> s = <> | ||||||||||
(x^y)s = (x s)^(y s) | ||||||||||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is much better, but we are no nearer understanding selectors from this. Can we assert that a selected sequence is a subsequence (not necessarily contiguous) of the original? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, but each value in the selected sequence is a descendant (or equal to) of a value in the original sequence. |
||||||||||
``` | ||||||||||
|
||||||||||
## JSON object construction | ||||||||||
|
||||||||||
If `m` and `n` are JSON objects with no keys in common, then `m ∪ n` is the JSON object containing | ||||||||||
all the mappings of `m` and `n` (but no others). | ||||||||||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything to say about common keys? The overuse of the term 'mapping' is potentially confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to define a partial
Suggested change
|
||||||||||
|
||||||||||
## compound path semantics | ||||||||||
|
||||||||||
If JSONPath `p` is selector `s` followed by JSONPath `t`, then for all JSON values `v`: | ||||||||||
``` | ||||||||||
<v>p = (<v>s)t | ||||||||||
``` | ||||||||||
Zteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
## root selector semantics | ||||||||||
`$` is effectively a no-op. If `t` is a JSONPath (without a leading `$`), then: | ||||||||||
``` | ||||||||||
<v>$t = <v>t | ||||||||||
``` | ||||||||||
Comment on lines
+39
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of thing is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are at least two schools of thought. I have tended to think of The original JSONPath article required all JSONPaths to start with |
||||||||||
Question: do we need to use something like quasi quotes to clarify the above? | ||||||||||
Zteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
## selectors | ||||||||||
|
||||||||||
The following sections describe primitive selectors which can be strung together to form a JSONPath. | ||||||||||
Zteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
### dot child | ||||||||||
If `o` is a JSON object which does not have key `k`, then: | ||||||||||
``` | ||||||||||
<o>.k = <> | ||||||||||
``` | ||||||||||
and: | ||||||||||
``` | ||||||||||
<o ∪ {k:v}>.k = <v> | ||||||||||
``` | ||||||||||
|
||||||||||
### union | ||||||||||
``` | ||||||||||
<a>[u, v] = (<a>[u]) ^ (<a>[v]) | ||||||||||
``` | ||||||||||
|
||||||||||
### bracket child | ||||||||||
If `o` is a JSON object which does not have key `k` (for certain forms of k...), then: | ||||||||||
``` | ||||||||||
<o>[k] = <> | ||||||||||
``` | ||||||||||
and: | ||||||||||
``` | ||||||||||
<o ∪ {k:v}>[k] = <v> | ||||||||||
Zteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
``` | ||||||||||
|
||||||||||
### array slice | ||||||||||
If `a` is an array, then: | ||||||||||
``` | ||||||||||
... details! ... | ||||||||||
``` | ||||||||||
|
||||||||||
If `a` is not an array and `sl` is a slice expression, then: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||
``` | ||||||||||
<a>[sl] = <> | ||||||||||
``` | ||||||||||
|
||||||||||
### recursive descent | ||||||||||
If `z` is a scalar: | ||||||||||
``` | ||||||||||
<z>.. = <z> | ||||||||||
``` | ||||||||||
If `o` is an empty object: | ||||||||||
``` | ||||||||||
<o>.. = <> | ||||||||||
``` | ||||||||||
|
||||||||||
If `o` is a JSON object which does not have key `k`, then: | ||||||||||
If `o` is an object comprised of `k:v` and an object p: | ||||||||||
``` | ||||||||||
<o ∪ {k:v}>.. = (<v>)^(<v>..)^(<o>..) | ||||||||||
``` | ||||||||||
Note: since an object can be deconstructed to the form `o ∪ {k:v}` for arbitrary key `k` in | ||||||||||
the original object, the ordering of the result is only partially defined. | ||||||||||
Zteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
If `a` is an empty array: | ||||||||||
``` | ||||||||||
<a>.. = <> | ||||||||||
``` | ||||||||||
If `h` is a JSON value and `t` is a JSON array: | ||||||||||
``` | ||||||||||
(<h>^t).. = (<h>)^(<h>..)^(t..) | ||||||||||
``` |
Uh oh!
There was an error while loading. Please reload this page.