You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Ben Weidig (Jira)" <ji...@apache.org> on 2023/01/29 12:06:00 UTC
[jira] [Updated] (TAP5-2747) KeyPath-based traversal of JSONCollection
[ https://issues.apache.org/jira/browse/TAP5-2747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Ben Weidig updated TAP5-2747:
-----------------------------
Description:
As navigation nested {{JSONObject}} structures can be tedious, so I propose adding a String-based KeyPath traversal system.
For example:
{code:java}
JSONObject json = ...
// {
// outer: { inner: "here" },
// array: [
// 1,
// { innerArray: ["A", "B", "C"] },
// ["Z", "Y", "X"]
// ]
// }
var result = json.getByKeyPath("array[1].innerArray[5]?");
// Equivalent to
var result = json.getByKeyPath("array.[1].innerArray.[5]?");{code}
The {{getByKeyPath}} method returns an Object, but the other types are available, too.
The following types of keypaths should be supported:
* {{JSONObject}} navigation, e.g. {{outer.inner -> "here"}}
* {{JSONArray}} indices, e.g. {{array[0] -> 1}}
* {{JSONArray}} indices without key, e.g. {{array.[0] -> 1}}
* Optionality, e.g, {{outer.nonExistant? -> null}}
The different types are combinable as needed.
By default, the KeyPath is delimited by "." but there should also be a {{getByKeyPath(String getKeyPath, String delimiter)}} to support "." in JSON keys.
I already have a proof-of-concept working. However, it requires some cleanup and a lot of testing before being ready.
was:
As navigation nested JSONObject structures can be tedious, so I propose adding a String-based KeyPath traversal system.
For example:
{code:java}
JSONObject json = ...
// {
// outer: { inner: "here" },
// array: [
// 1,
// { innerArray: ["A", "B", "C"] },
// ["Z", "Y", "X"]
// ]
// }
var result = json.getByKeyPath("array[1].innerArray[5]?");
// Equivalent to
var result = json.getByKeyPath("array[1].innerArray[5]?");{code}
The getByKeyPath method returns an Object, but the other types are available, too.
The following types of keypaths should be supported:
* JSONObject navigation, e.g. "outer.inner" -> "here"
* JSONArray indices, e.g. "array[0]" -> 1
* JSONArray indices without key, e.g. "array.[0]" -> 1
* Optionality, e.g, "outer.nonExistant?" -> null
I already have a proof-of-concept working. However, it requires some cleanup and a lot of testing before being ready.
> KeyPath-based traversal of JSONCollection
> -----------------------------------------
>
> Key: TAP5-2747
> URL: https://issues.apache.org/jira/browse/TAP5-2747
> Project: Tapestry 5
> Issue Type: New Feature
> Components: tapestry-json
> Affects Versions: 5.8.2
> Reporter: Ben Weidig
> Assignee: Ben Weidig
> Priority: Minor
>
> As navigation nested {{JSONObject}} structures can be tedious, so I propose adding a String-based KeyPath traversal system.
> For example:
> {code:java}
> JSONObject json = ...
> // {
> // outer: { inner: "here" },
> // array: [
> // 1,
> // { innerArray: ["A", "B", "C"] },
> // ["Z", "Y", "X"]
> // ]
> // }
> var result = json.getByKeyPath("array[1].innerArray[5]?");
> // Equivalent to
> var result = json.getByKeyPath("array.[1].innerArray.[5]?");{code}
>
> The {{getByKeyPath}} method returns an Object, but the other types are available, too.
> The following types of keypaths should be supported:
> * {{JSONObject}} navigation, e.g. {{outer.inner -> "here"}}
> * {{JSONArray}} indices, e.g. {{array[0] -> 1}}
> * {{JSONArray}} indices without key, e.g. {{array.[0] -> 1}}
> * Optionality, e.g, {{outer.nonExistant? -> null}}
> The different types are combinable as needed.
> By default, the KeyPath is delimited by "." but there should also be a {{getByKeyPath(String getKeyPath, String delimiter)}} to support "." in JSON keys.
> I already have a proof-of-concept working. However, it requires some cleanup and a lot of testing before being ready.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)