Anticipating more complex data to follow
Tuesday, 22 March 2022 · 6 messages
PD
Patrick Durusau22 Mar 2022 01:15 #
Greetings!
While working on some large but fairly simple data, I encountered BaseX using the underscore "_" as an element name when importing JSON.
Not leaving well enough alone for present purposes, I encountered this post about anonymous objects in MarkLogic and how they resolve the problem.
https://developer.marklogic.com/recipe/query-array-anonymous-objects/
Is there already a recommended solution for this problem?
Or should I wait until I actually encounter it and ask again?
Hope everyone is at the start of a great week!
Patrick
--
Patrick Durusau
patrick at durusau.net
Technical Advisory Board, OASIS (TAB)
Editor, OpenDocument Format TC (OASIS), Project Editor ISO/IEC 26300 Co-Editor, ISO/IEC 13250-1, 13250-5 (Topic Maps)
Another Word For It (blog): http://tm.durusau.net
Homepage: http://www.durusau.net
Twitter: patrickDurusau
CG
Christian Grün22 Mar 2022 21:32 #
Hi Patrick,
Which problem would you like to solve exactly?
Maybe I should read the MarkLogic article in more detail, though.
Best,
Christian
Quoted text · Patrick Durusau · 31 lines
On Tue, Mar 22, 2022 at 12:15 AM Patrick Durusau <patrick at durusau.net> wrote: > > Greetings! > > While working on some large but fairly simple data, I encountered BaseX > using the underscore "_" as an element name when importing JSON. > > Not leaving well enough alone for present purposes, I encountered this > post about anonymous objects in MarkLogic and how they resolve the problem. > > https://developer.marklogic.com/recipe/query-array-anonymous-objects/ > > Is there already a recommended solution for this problem? > > Or should I wait until I actually encounter it and ask again? > > Hope everyone is at the start of a great week! > > Patrick > > -- > Patrick Durusau > patrick at durusau.net > Technical Advisory Board, OASIS (TAB) > Editor, OpenDocument Format TC (OASIS), Project Editor ISO/IEC 26300 > Co-Editor, ISO/IEC 13250-1, 13250-5 (Topic Maps) > > Another Word For It (blog): http://tm.durusau.net > Homepage: http://www.durusau.net > Twitter: patrickDurusau >
MH
Quoted text · Patrick Durusau · 4 lines
On 22.03.2022 21:48, Patrick Durusau wrote: > I'm anticipating incorporation of JSON sources with anonymous nodes > and if they all appear with the element name _, how do I distinguish > one from another, structurally speaking?
Are you not able to use XPath/XQuery 3.1 map/array lookup operators directly on your JSON e.g.
?parties[exists(?*[?name = 'name1' and ?role = 'CN'])]
CG
I would write it as follows:
let $string := '{ "parties": [
{ "id": 0, "role": "CN", "name": "name1" },
{ "id": 1, "role": "SH", "name": "name2" }
] }'
let $data := json:parse($string)
return $data/json/parties[_[name = 'name1'][role = 'CN']]Martin provided the solution for the XQuery map/array format:
let $data := json:parse($string, map { 'format': 'xquery'})
return $data?parties[exists(?*[?name = 'name1'][?role = 'CN'])]Quoted text · Patrick Durusau · 14 lines
On Tue, Mar 22, 2022 at 9:48 PM Patrick Durusau <patrick at durusau.net> wrote: > > I'm anticipating incorporation of JSON sources with anonymous nodes and > if they all appear with the element name _, how do I distinguish one > from another, structurally speaking? > > MarkLogic offers some specific workarounds but those are unique (I > suspect) to MarkLogic. > > The MarkLogic post has an example of the problem I anticipate hitting, > especially in biblical studies. > > Thanks! > Patrick
PD
I'm anticipating incorporation of JSON sources with anonymous nodes and if they all appear with the element name _, how do I distinguish one from another, structurally speaking?
MarkLogic offers some specific workarounds but those are unique (I suspect) to MarkLogic.
The MarkLogic post has an example of the problem I anticipate hitting, especially in biblical studies.
Thanks!
Patrick
Quoted text · Christian Grün · 40 lines
On 3/22/22 16:32, Christian Grün wrote: > Hi Patrick, > > Which problem would you like to solve exactly? > Maybe I should read the MarkLogic article in more detail, though. > > Best, > Christian > > > On Tue, Mar 22, 2022 at 12:15 AM Patrick Durusau <patrick at durusau.net> wrote: >> Greetings! >> >> While working on some large but fairly simple data, I encountered BaseX >> using the underscore "_" as an element name when importing JSON. >> >> Not leaving well enough alone for present purposes, I encountered this >> post about anonymous objects in MarkLogic and how they resolve the problem. >> >> https://developer.marklogic.com/recipe/query-array-anonymous-objects/ >> >> Is there already a recommended solution for this problem? >> >> Or should I wait until I actually encounter it and ask again? >> >> Hope everyone is at the start of a great week! >> >> Patrick >> >> -- >> Patrick Durusau >> patrick at durusau.net >> Technical Advisory Board, OASIS (TAB) >> Editor, OpenDocument Format TC (OASIS), Project Editor ISO/IEC 26300 >> Co-Editor, ISO/IEC 13250-1, 13250-5 (Topic Maps) >> >> Another Word For It (blog): http://tm.durusau.net >> Homepage: http://www.durusau.net >> Twitter: patrickDurusau >>
--
Patrick Durusau
patrick at durusau.net
Technical Advisory Board, OASIS (TAB)
Editor, OpenDocument Format TC (OASIS), Project Editor ISO/IEC 26300 Co-Editor, ISO/IEC 13250-1, 13250-5 (Topic Maps)
Another Word For It (blog): http://tm.durusau.net
Homepage: http://www.durusau.net
Twitter: patrickDurusau
PD
Thanks!
Appreciate the quick response!
Patrick
Quoted text · Christian Grün · 30 lines
On 3/22/22 17:08, Christian Grün wrote: > I would write it as follows: > > let $string := '{ "parties": [ > { "id": 0, "role": "CN", "name": "name1" }, > { "id": 1, "role": "SH", "name": "name2" } > ] }' > let $data := json:parse($string) > return $data/json/parties[_[name = 'name1'][role = 'CN']] > > Martin provided the solution for the XQuery map/array format: > > let $data := json:parse($string, map { 'format': 'xquery'}) > return $data?parties[exists(?*[?name = 'name1'][?role = 'CN'])] > > > > On Tue, Mar 22, 2022 at 9:48 PM Patrick Durusau <patrick at durusau.net> wrote: >> I'm anticipating incorporation of JSON sources with anonymous nodes and >> if they all appear with the element name _, how do I distinguish one >> from another, structurally speaking? >> >> MarkLogic offers some specific workarounds but those are unique (I >> suspect) to MarkLogic. >> >> The MarkLogic post has an example of the problem I anticipate hitting, >> especially in biblical studies. >> >> Thanks! >> Patrick
--
Patrick Durusau
patrick at durusau.net
Technical Advisory Board, OASIS (TAB)
Editor, OpenDocument Format TC (OASIS), Project Editor ISO/IEC 26300 Co-Editor, ISO/IEC 13250-1, 13250-5 (Topic Maps)
Another Word For It (blog): http://tm.durusau.net
Homepage: http://www.durusau.net
Twitter: patrickDurusau
Written for BaseX 9.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery