Skip to content
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

JSON: function "query" #157

Merged
merged 55 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d83c0b6
Function "query"
ralfhandl Sep 27, 2021
1641c49
Added "value" function, defined processing rules
ralfhandl Sep 28, 2021
b41aad8
Recommended and optional expressions
ralfhandl Sep 29, 2021
5f153de
Aligned terminology with draft RFC
ralfhandl Sep 29, 2021
b1e1ea9
Examples
ralfhandl Oct 1, 2021
ec1ec9c
Long description of the vocabulary
ralfhandl Oct 1, 2021
778d44c
Update Org.OData.JSON.V1.Schema-sample.xml
ralfhandl Oct 1, 2021
d761c8d
Minor edits
ralfhandl Oct 1, 2021
5ede455
Update Org.OData.JSON.V1.xml
ralfhandl Oct 1, 2021
f9d2a37
Function "value" isn't composable
ralfhandl Oct 1, 2021
b23a8bd
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Oct 14, 2021
aa6cb39
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Oct 15, 2021
c372fbc
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Nov 10, 2021
a3b0ed4
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Dec 6, 2021
7f02bee
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Dec 13, 2021
f8523ba
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Dec 17, 2021
c5b853f
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Feb 3, 2022
c98a1e6
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Feb 10, 2022
82e83fc
Merge remote-tracking branch 'origin/main' into ODATA-1336/json-query
HeikoTheissen May 6, 2022
270b5b4
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Aug 31, 2022
806188c
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Sep 7, 2022
d1848a3
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Dec 20, 2022
a661ad0
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Jan 10, 2023
bd12070
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Mar 21, 2023
470a277
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Apr 27, 2023
ab4a20f
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Jul 4, 2023
8b62d83
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Sep 7, 2023
99fa5ee
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Sep 7, 2023
c5b8c7f
Use JSONPath draft 20
ralfhandl Sep 22, 2023
b83f15a
Updated URLs
ralfhandl Sep 22, 2023
d9c8a69
Additional JSONPath constructs are examples only, no restriction
ralfhandl Sep 22, 2023
1b52e7f
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Dec 1, 2023
3fa98e6
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Feb 29, 2024
6f9faac
Typo
ralfhandl Feb 29, 2024
873715f
Typo
ralfhandl Feb 29, 2024
bb8577f
JSONPath is now an RFC
ralfhandl Feb 29, 2024
5b389f2
Update links
ralfhandl Feb 29, 2024
f2c28dd
Align with RFC text
ralfhandl Feb 29, 2024
d3a7336
MUST for minimum functionality
ralfhandl Mar 7, 2024
e2ac582
JSON data instead of JSON stream
ralfhandl Mar 7, 2024
24d78ab
name=value syntax for function calls
ralfhandl Mar 14, 2024
6c8dc89
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Mar 14, 2024
d41ef8d
Update vocabularies/Org.OData.JSON.V1.xml
ralfhandl Mar 14, 2024
ac67e0b
Update Org.OData.JSON.V1.xml
ralfhandl Mar 14, 2024
e0c93ac
Heiko's comment
ralfhandl Mar 14, 2024
1b5c571
Return-type-specific value functions
HeikoTheissen Apr 4, 2024
269ac57
Example for valueNumber
HeikoTheissen Apr 4, 2024
882237a
Apply suggestions from code review
ralfhandl Apr 4, 2024
f581770
Rebuilt
ralfhandl Apr 4, 2024
b1276f0
Formatting
ralfhandl Apr 4, 2024
b61160b
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Apr 8, 2024
52288cf
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Apr 11, 2024
ab134d0
Merge branch 'main' into ODATA-1336/json-query
ralfhandl Apr 11, 2024
f232900
Revert unintended line breaks
ralfhandl Apr 12, 2024
38c4827
Reference example, don't copy it
HeikoTheissen Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions vocabularies/Org.OData.JSON.V1.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
{
"$Kind": "Function",
"$IsBound": true,
"@Core.Description": "Query a stream value of media type `application/json`, returning an OData primitive value",
"@Core.LongDescription": "Extracts a single OData primitive value from the `input` JSON value:\n- If `path` only consists of the root identifier followed by name and index selectors and identifies a single scalar JSON value (string, number, boolean, or `null`) within `input`, it returns the identified single value, cast to an OData primitive value (see below).\n- If `path` identifies multiple nodes within `input` (by using descendant, wildcard, union, array subset, or filter selectors), identifies an object or array, or does not identify any node, the function returns `null`.\n- If `input` is not a valid JSON value, the function returns `null`.\n- If `path` is `null`, not a valid [JSONPath expression](#Path), or does not match the structure of `input` (for example applying an index selector to a scalar value), the function returns `null`.\n\nIf a single scalar JSON value is identified by `path` within `input`, the function returns that value as an OData primitive value:\n- `null` is returned as `null`\n- `true` or `false` are returned as the corresponding `Edm.Boolean` values \n- numbers are returned as `Edm.Decimal` values with unspecified precision and floating scale\n- strings are returned as `Edm.String` values\n ",
"@Core.Description": "Query a stream value of media type `application/json`, returning a string",
"@Core.LongDescription": "Extracts a single OData primitive value from the `input` JSON value and casts it to a string:\n- If `path` only consists of the root identifier followed by name and index selectors and identifies a single scalar JSON value (string, number, boolean, or `null`) within `input`, it returns the identified single value, cast to an OData primitive value (see below).\n- If `path` identifies multiple nodes within `input` (by using descendant, wildcard, union, array subset, or filter selectors), identifies an object or array, or does not identify any node, the function returns `null`.\n- If `input` is not a valid JSON value, the function returns `null`.\n- If `path` is `null`, not a valid [JSONPath expression](#Path), or does not match the structure of `input` (for example applying an index selector to a scalar value), the function returns `null`.",
"$Parameter": [
{
"$Name": "input",
Expand All @@ -94,7 +94,62 @@
"$ReturnType": {
"$Type": "Edm.PrimitiveType",
"$Nullable": true,
ralfhandl marked this conversation as resolved.
Show resolved Hide resolved
"@Core.Description": "OData primitive value resulting from applying `path` to `input`"
"@Core.Description": "String value resulting from applying `path` to `input`"
}
}
],
"valueNumber": [
{
"$Kind": "Function",
"$IsBound": true,
"@Core.Description": "Query a stream value of media type `application/json`, returning a number",
"@Core.LongDescription": "Like [`value`](#value), but casts the extracted value to an `Edm.Decimal` with unspecified precision and floating scale.\n Returns null if that cast fails.",
"$Parameter": [
{
"$Name": "input",
"$Type": "JSON.JSON",
"$Nullable": true,
"@Core.Description": "JSON input"
},
{
"$Name": "path",
"$Type": "JSON.Path",
"$Nullable": true,
"@Core.Description": "JSONPath expression to be applied to value of `expr`"
}
],
"$ReturnType": {
"$Type": "Edm.Decimal",
"$Nullable": true,
"$Scale": "floating",
"@Core.Description": "Numeric value resulting from applying `path` to `input`"
}
}
],
"valueBoolean": [
{
"$Kind": "Function",
"$IsBound": true,
"@Core.Description": "Query a stream value of media type `application/json`, returning a Boolean",
"@Core.LongDescription": "Like [`value`](#value), but casts the extracted value to an `Edm.Boolean`.\n Returns null if that cast fails.",
"$Parameter": [
{
"$Name": "input",
"$Type": "JSON.JSON",
"$Nullable": true,
"@Core.Description": "JSON input"
},
{
"$Name": "path",
"$Type": "JSON.Path",
"$Nullable": true,
"@Core.Description": "JSONPath expression to be applied to value of `expr`"
}
],
"$ReturnType": {
"$Type": "Edm.Boolean",
"$Nullable": true,
"@Core.Description": "Boolean value resulting from applying `path` to `input`"
}
}
],
Expand Down
49 changes: 36 additions & 13 deletions vocabularies/Org.OData.JSON.V1.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,59 @@ Parameter|Type|Description
<a name="value"></a>
### [value](./Org.OData.JSON.V1.xml#L184:~:text=<Function%20Name="-,value,-")

Query a stream value of media type `application/json`, returning an OData primitive value
Query a stream value of media type `application/json`, returning a string

Extracts a single OData primitive value from the `input` JSON value:
Extracts a single OData primitive value from the `input` JSON value and casts it to a string:
- If `path` only consists of the root identifier followed by name and index selectors and identifies a single scalar JSON value (string, number, boolean, or `null`) within `input`, it returns the identified single value, cast to an OData primitive value (see below).
- If `path` identifies multiple nodes within `input` (by using descendant, wildcard, union, array subset, or filter selectors), identifies an object or array, or does not identify any node, the function returns `null`.
- If `input` is not a valid JSON value, the function returns `null`.
- If `path` is `null`, not a valid [JSONPath expression](#Path), or does not match the structure of `input` (for example applying an index selector to a scalar value), the function returns `null`.

If a single scalar JSON value is identified by `path` within `input`, the function returns that value as an OData primitive value:
- `null` is returned as `null`
- `true` or `false` are returned as the corresponding `Edm.Boolean` values
- numbers are returned as `Edm.Decimal` values with unspecified precision and floating scale
- strings are returned as `Edm.String` values

Parameter|Type|Description
:--------|:---|:----------
**[input](./Org.OData.JSON.V1.xml#L194:~:text=<Function%20Name="-,value,-")**|[JSON?](#JSON)|**Binding parameter:** JSON input
[path](./Org.OData.JSON.V1.xml#L197:~:text=<Function%20Name="-,value,-")|[Path?](#Path)|JSONPath expression to be applied to value of `expr`
[&rarr;](./Org.OData.JSON.V1.xml#L201:~:text=<Function%20Name="-,value,-")|PrimitiveType?|String value resulting from applying `path` to `input`


<a name="valueNumber"></a>
### [valueNumber](./Org.OData.JSON.V1.xml#L206:~:text=<Function%20Name="-,valueNumber,-")

Query a stream value of media type `application/json`, returning a number

Like [`value`](#value), but casts the extracted value to an `Edm.Decimal` with unspecified precision and floating scale.
Returns null if that cast fails.

Parameter|Type|Description
:--------|:---|:----------
**[input](./Org.OData.JSON.V1.xml#L212:~:text=<Function%20Name="-,valueNumber,-")**|[JSON?](#JSON)|**Binding parameter:** JSON input
[path](./Org.OData.JSON.V1.xml#L215:~:text=<Function%20Name="-,valueNumber,-")|[Path?](#Path)|JSONPath expression to be applied to value of `expr`
[&rarr;](./Org.OData.JSON.V1.xml#L218:~:text=<Function%20Name="-,valueNumber,-")|Decimal?|Numeric value resulting from applying `path` to `input`


<a name="valueBoolean"></a>
### [valueBoolean](./Org.OData.JSON.V1.xml#L222:~:text=<Function%20Name="-,valueBoolean,-")

Query a stream value of media type `application/json`, returning a Boolean

Like [`value`](#value), but casts the extracted value to an `Edm.Boolean`.
Returns null if that cast fails.

Parameter|Type|Description
:--------|:---|:----------
**[input](./Org.OData.JSON.V1.xml#L201:~:text=<Function%20Name="-,value,-")**|[JSON?](#JSON)|**Binding parameter:** JSON input
[path](./Org.OData.JSON.V1.xml#L204:~:text=<Function%20Name="-,value,-")|[Path?](#Path)|JSONPath expression to be applied to value of `expr`
[&rarr;](./Org.OData.JSON.V1.xml#L208:~:text=<Function%20Name="-,value,-")|PrimitiveType?|OData primitive value resulting from applying `path` to `input`
**[input](./Org.OData.JSON.V1.xml#L228:~:text=<Function%20Name="-,valueBoolean,-")**|[JSON?](#JSON)|**Binding parameter:** JSON input
[path](./Org.OData.JSON.V1.xml#L231:~:text=<Function%20Name="-,valueBoolean,-")|[Path?](#Path)|JSONPath expression to be applied to value of `expr`
[&rarr;](./Org.OData.JSON.V1.xml#L234:~:text=<Function%20Name="-,valueBoolean,-")|Boolean?|Boolean value resulting from applying `path` to `input`


<a name="JSON"></a>
## [JSON](./Org.OData.JSON.V1.xml#L214:~:text=<TypeDefinition%20Name="-,JSON,-")
## [JSON](./Org.OData.JSON.V1.xml#L239:~:text=<TypeDefinition%20Name="-,JSON,-")
**Type:** Stream

Textual data of media type `application/json`

<a name="Path"></a>
## [Path](./Org.OData.JSON.V1.xml#L225:~:text=<TypeDefinition%20Name="-,Path,-")
## [Path](./Org.OData.JSON.V1.xml#L250:~:text=<TypeDefinition%20Name="-,Path,-")
**Type:** String

[JSONPath](https://datatracker.ietf.org/doc/html/rfc9535) expression
Expand Down
47 changes: 36 additions & 11 deletions vocabularies/Org.OData.JSON.V1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,13 @@ receiving

<Function Name="value" IsBound="true">
<Annotation Term="Core.Description"
String="Query a stream value of media type `application/json`, returning an OData primitive value" />
String="Query a stream value of media type `application/json`, returning a string" />
<Annotation Term="Core.LongDescription">
<String>Extracts a single OData primitive value from the `input` JSON value:
<String>Extracts a single OData primitive value from the `input` JSON value and casts it to a string:
- If `path` only consists of the root identifier followed by name and index selectors and identifies a single scalar JSON value (string, number, boolean, or `null`) within `input`, it returns the identified single value, cast to an OData primitive value (see below).
ralfhandl marked this conversation as resolved.
Show resolved Hide resolved
- If `path` identifies multiple nodes within `input` (by using descendant, wildcard, union, array subset, or filter selectors), identifies an object or array, or does not identify any node, the function returns `null`.
- If `input` is not a valid JSON value, the function returns `null`.
- If `path` is `null`, not a valid [JSONPath expression](#Path), or does not match the structure of `input` (for example applying an index selector to a scalar value), the function returns `null`.

If a single scalar JSON value is identified by `path` within `input`, the function returns that value as an OData primitive value:
- `null` is returned as `null`
- `true` or `false` are returned as the corresponding `Edm.Boolean` values
- numbers are returned as `Edm.Decimal` values with unspecified precision and floating scale
- strings are returned as `Edm.String` values
</String>
- If `path` is `null`, not a valid [JSONPath expression](#Path), or does not match the structure of `input` (for example applying an index selector to a scalar value), the function returns `null`.</String>
</Annotation>
<Parameter Name="input" Type="JSON.JSON">
<Annotation Term="Core.Description" String="JSON input" />
Expand All @@ -207,7 +200,39 @@ If a single scalar JSON value is identified by `path` within `input`, the functi
</Parameter>
<ReturnType Type="Edm.PrimitiveType">
ralfhandl marked this conversation as resolved.
Show resolved Hide resolved
<Annotation Term="Core.Description"
String="OData primitive value resulting from applying `path` to `input`" />
String="String value resulting from applying `path` to `input`" />
</ReturnType>
</Function>
<Function Name="valueNumber" IsBound="true">
<Annotation Term="Core.Description" String="Query a stream value of media type `application/json`, returning a number" />
<Annotation Term="Core.LongDescription">
<String>Like [`value`](#value), but casts the extracted value to an `Edm.Decimal` with unspecified precision and floating scale.
Returns null if that cast fails.</String>
</Annotation>
<Parameter Name="input" Type="JSON.JSON">
<Annotation Term="Core.Description" String="JSON input" />
</Parameter>
<Parameter Name="path" Type="JSON.Path">
<Annotation Term="Core.Description" String="JSONPath expression to be applied to value of `expr`" />
</Parameter>
<ReturnType Type="Edm.Decimal" Scale="floating">
<Annotation Term="Core.Description" String="Numeric value resulting from applying `path` to `input`" />
</ReturnType>
</Function>
<Function Name="valueBoolean" IsBound="true">
<Annotation Term="Core.Description" String="Query a stream value of media type `application/json`, returning a Boolean" />
<Annotation Term="Core.LongDescription">
<String>Like [`value`](#value), but casts the extracted value to an `Edm.Boolean`.
Returns null if that cast fails.</String>
</Annotation>
<Parameter Name="input" Type="JSON.JSON">
<Annotation Term="Core.Description" String="JSON input" />
</Parameter>
<Parameter Name="path" Type="JSON.Path">
<Annotation Term="Core.Description" String="JSONPath expression to be applied to value of `expr`" />
</Parameter>
<ReturnType Type="Edm.Boolean">
<Annotation Term="Core.Description" String="Boolean value resulting from applying `path` to `input`" />
</ReturnType>
</Function>

Expand Down