Update/Delete JSON
What is the best way to update JSON objects (only some object values) by unique id?
What is the best way to delete JSON objects by unique id?
Wray Johnson (m) 704-293-9008
In XQuery, JSON objects are represented as immutable maps. Please check out the documentations to learn how these data structures can be changed [1,2]. _______________
[1] http://docs.basex.org/wiki/Map_Module [2] https://www.w3.org/TR/xpath-functions-31/#maps-and-arrays
Quoted text · E. Wray Johnson · 7 lines
On Sun, Nov 12, 2017 at 3:42 AM, E. Wray Johnson <wray.johnson at gmail.com> wrote: > What is the best way to update JSON objects (only some object values) by unique id? > > What is the best way to delete JSON objects by unique id? > > Wray Johnson > (m) 704-293-9008
Christian,
The JSON Module suggests that JSON objects are represented as XML-documents with a certain structure, not as immutable maps. Is there support in BaseX for json:parse and json:serialize for parsing JSON in textual form into immutable maps and back to JSON in textual form?
Kind regards, Maurice van Keulen
Quoted text · Christian Grün · 1 line
On 13 Nov 2017 23:31 +0100, Christian Grün <christian.gruen at gmail.com>, wrote:
Quoted text · E. Wray Johnson · 1 line
On Sun, Nov 12, 2017 at 3:42 AM, E. Wray Johnson <wray.johnson at gmail.com> wrote:
Hi all,
I think we should make the difference between memory and persisted JSON representations.
From what I know, only a JSON document representation will be persisted, And map representations are only memory ones.
Just use the map (or xquery starting v9) format option at parsing time.
Best regards,
Fabrice
Quoted text · m.vankeulen at utwente.nl · 26 lines
De : basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de m.vankeulen at utwente.nl Envoyé : mercredi 15 novembre 2017 08:30 À : wray.johnson at gmail.com; christian.gruen at gmail.com Cc : basex-talk at mailman.uni-konstanz.de Objet : Re: [basex-talk] Update/Delete JSON Christian, The JSON Module suggests that JSON objects are represented as XML-documents with a certain structure, not as immutable maps. Is there support in BaseX for json:parse and json:serialize for parsing JSON in textual form into immutable maps and back to JSON in textual form? Kind regards, Maurice van Keulen -- ---------------------------------------------------------------------- Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands Email: m.vankeulen at utwente.nl<mailto:m.vankeulen at utwente.nl>, Phone: +31 534893688, Fax: +31 534892927 Room: ZI 2013, WWW: http://www.cs.utwente.nl/~keulen On 13 Nov 2017 23:31 +0100, Christian Grün <christian.gruen at gmail.com<mailto:christian.gruen at gmail.com>>, wrote: In XQuery, JSON objects are represented as immutable maps. Please check out the documentations to learn how these data structures can be changed [1,2]. [1] http://docs.basex.org/wiki/Map_Module [2] https://www.w3.org/TR/xpath-functions-31/#maps-and-arrays On Sun, Nov 12, 2017 at 3:42 AM, E. Wray Johnson <wray.johnson at gmail.com<mailto:wray.johnson at gmail.com>> wrote: What is the best way to update JSON objects (only some object values) by unique id? What is the best way to delete JSON objects by unique id? Wray Johnson (m) 704-293-9008
Hi Maurice,
Depending on the chosen format, different outputs will be generated by json:parse. Traditionally, it is true that only XML was generated by this function, but in newer versions (and in alignment with the XQuery 3.1 specs and the fn:parse-json function), it is also possible now to convert JSON data to atomic XQuery items (maps, arrays, strings, numbers and booleans) [1,2]. The resulting representation will be more memory-efficient, and access to XQuery maps is blazing fast, but it won’t be possible to store this representation to a database.
Hope this helps, greetings, Christian
[1] http://docs.basex.org/wiki/JSON_Module#XQuery [2] http://docs.basex.org/wiki/JSON_Module#XQuery_Format
Quoted text · m.vankeulen · 47 lines
On Wed, Nov 15, 2017 at 8:30 AM, <m.vankeulen at utwente.nl> wrote: > Christian, > > The JSON Module suggests that JSON objects are represented as XML-documents > with a certain structure, not as immutable maps. Is there support in BaseX > for json:parse and json:serialize for parsing JSON in textual form into > immutable maps and back to JSON in textual form? > > Kind regards, > Maurice van Keulen > > -- > > ---------------------------------------------------------------------- > > Dr.Ir. M. van Keulen - Associate Professor, Data Management Technology > > Univ. of Twente, Dept of EEMCS, POBox 217, 7500 AE Enschede, Netherlands > > Email: m.vankeulen at utwente.nl, Phone: +31 534893688, Fax: +31 534892927 > > Room: ZI 2013, WWW: http://www.cs.utwente.nl/~keulen > > > On 13 Nov 2017 23:31 +0100, Christian Grün <christian.gruen at gmail.com>, > wrote: > > In XQuery, JSON objects are represented as immutable maps. Please > check out the documentations to learn how these data structures can be > changed [1,2]. > _______________ > > [1] http://docs.basex.org/wiki/Map_Module > [2] https://www.w3.org/TR/xpath-functions-31/#maps-and-arrays > > > > On Sun, Nov 12, 2017 at 3:42 AM, E. Wray Johnson <wray.johnson at gmail.com> > wrote: > > What is the best way to update JSON objects (only some object values) by > unique id? > > What is the best way to delete JSON objects by unique id? > > Wray Johnson > (m) 704-293-9008
Quoted text · basex-talk-bounces at mailman.uni-konstanz.de on behalf of Christian Grün · 1 line
On 11/15/17, 4:24 AM, "basex-talk-bounces at mailman.uni-konstanz.de on behalf of Christian Grün" <basex-talk-bounces at mailman.uni-konstanz.de on behalf of christian.gruen at gmail.com> wrote:
Hi Maurice,
Depending on the chosen format, different outputs will be generated by json:parse. Traditionally, it is true that only XML was generated by this function, but in newer versions (and in alignment with the XQuery 3.1 specs and the fn:parse-json function), it is also possible now to convert JSON data to atomic XQuery items (maps, arrays, strings, numbers and booleans) [1,2]. The resulting representation will be more memory-efficient, and access to XQuery maps is blazing fast, but it won’t be possible to store this representation to a database.
Hope this helps, greetings, Christian
[1] https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_JSON-5FModule-23XQuery&d=DwIFaQ&c=DS6PUFBBr_KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq-Up2QMq9rrGyfWK0KtSpT7dxRglA&m=gYEI_kXgIHiAXP9cz0NdqkWgkjfpAGxnOd1-b8pW3mo&s=_ugHBUSWLu-V4vzcR6jpfcc11M-g6zbiag5lU7COcLA&e= [2] https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_JSON-5FModule-23XQuery-5FFormat&d=DwIFaQ&c=DS6PUFBBr_KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq-Up2QMq9rrGyfWK0KtSpT7dxRglA&m=gYEI_kXgIHiAXP9cz0NdqkWgkjfpAGxnOd1-b8pW3mo&s=o-pnuPNeYd74pBg0DLEEtwO3r4IKsaC7DPGIo7gxG6c&e=
Quoted text · Christian Grün · 10 lines
On Wed, Nov 15, 2017 at 8:30 AM, <m.vankeulen at utwente.nl> wrote: > Christian, > > The JSON Module suggests that JSON objects are represented as XML-documents > with a certain structure, not as immutable maps. Is there support in BaseX > for json:parse and json:serialize for parsing JSON in textual form into > immutable maps and back to JSON in textual form? > > Kind regards, > Maurice van Keulen
Aside from XQuery and BaseX converting JSON, because JSON is not just objects, I think there could be a problem with the concept of converting JSON to maps, also. For example, these JSON documents aren’t map-like:
1. true 2. ["a", "a", "a", "x"]
Kendall
Quoted text · Kendall Shaw · 4 lines
> Aside from XQuery and BaseX converting JSON, because JSON is not just objects, I think there could be a problem with the concept of converting JSON to maps, also. For example, these JSON documents aren’t map-like: > > 1. true > 2. ["a", "a", "a", "x"]
True! In the current version of BaseX, the option for converting JSON to XQuery item is still called 'map'. This is confusing, so (with BaseX 9.0) we changed it to 'xquery'.
Hi E. Wray,
Quoted text · E. Wray Johnson · 2 lines
> Can you give an example of how to convert JSON data to atomic XQuery items > (sepecifically strings, numbers and booleans)?
Sure:
let $options := map { 'format': 'map' }
for $json in (
'"string"', '1984', 'true'
)
return json:parse($json, $options)With BaseX 9.0, you’ll need to change 'map' to 'xquery'. You can also use fn:parse-json without second argument (see [1] for more examples).
Cheers, Christian
[1] https://www.w3.org/TR/xpath-functions-31/#func-parse-json
Quoted text · E. Wray Johnson · 59 lines
On Wed, Nov 15, 2017 at 6:26 PM, E. Wray Johnson <wray.johnson at gmail.com> wrote: > Christian, > > Can you give an example of how to convert JSON data to atomic XQuery items > (sepecifically strings, numbers and booleans)? Is it as simple as removing > the curly brackets to bound an object? > > On Wed, Nov 15, 2017 at 11:05 AM, Kendall Shaw <kendall.shaw at workday.com> > wrote: >> >> On 11/15/17, 4:24 AM, "basex-talk-bounces at mailman.uni-konstanz.de on >> behalf of Christian Grün" <basex-talk-bounces at mailman.uni-konstanz.de on >> behalf of christian.gruen at gmail.com> wrote: >> >> Hi Maurice, >> >> Depending on the chosen format, different outputs will be generated by >> json:parse. Traditionally, it is true that only XML was generated by >> this function, but in newer versions (and in alignment with the XQuery >> 3.1 specs and the fn:parse-json function), it is also possible now to >> convert JSON data to atomic XQuery items (maps, arrays, strings, >> numbers and booleans) [1,2]. The resulting representation will be more >> memory-efficient, and access to XQuery maps is blazing fast, but it >> won’t be possible to store this representation to a database. >> >> Hope this helps, greetings, >> Christian >> >> [1] >> https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_JSON-5FModule-23XQuery&d=DwIFaQ&c=DS6PUFBBr_KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq-Up2QMq9rrGyfWK0KtSpT7dxRglA&m=gYEI_kXgIHiAXP9cz0NdqkWgkjfpAGxnOd1-b8pW3mo&s=_ugHBUSWLu-V4vzcR6jpfcc11M-g6zbiag5lU7COcLA&e= >> [2] >> https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_JSON-5FModule-23XQuery-5FFormat&d=DwIFaQ&c=DS6PUFBBr_KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq-Up2QMq9rrGyfWK0KtSpT7dxRglA&m=gYEI_kXgIHiAXP9cz0NdqkWgkjfpAGxnOd1-b8pW3mo&s=o-pnuPNeYd74pBg0DLEEtwO3r4IKsaC7DPGIo7gxG6c&e= >> >> >> >> On Wed, Nov 15, 2017 at 8:30 AM, <m.vankeulen at utwente.nl> wrote: >> > Christian, >> > >> > The JSON Module suggests that JSON objects are represented as >> XML-documents >> > with a certain structure, not as immutable maps. Is there support in >> BaseX >> > for json:parse and json:serialize for parsing JSON in textual form >> into >> > immutable maps and back to JSON in textual form? >> > >> > Kind regards, >> > Maurice van Keulen >> >> Aside from XQuery and BaseX converting JSON, because JSON is not just >> objects, I think there could be a problem with the concept of converting >> JSON to maps, also. For example, these JSON documents aren’t map-like: >> >> 1. true >> 2. ["a", "a", "a", "x"] >> >> Kendall >> >
Christian,
Can you give an example of how to convert JSON data to atomic XQuery items (sepecifically strings, numbers and booleans)? Is it as simple as removing the curly brackets to bound an object?
Quoted text · Kendall Shaw · 57 lines
On Wed, Nov 15, 2017 at 11:05 AM, Kendall Shaw <kendall.shaw at workday.com> wrote: > On 11/15/17, 4:24 AM, "basex-talk-bounces at mailman.uni-konstanz.de on > behalf of Christian Grün" <basex-talk-bounces at mailman.uni-konstanz.de on > behalf of christian.gruen at gmail.com> wrote: > > Hi Maurice, > > Depending on the chosen format, different outputs will be generated by > json:parse. Traditionally, it is true that only XML was generated by > this function, but in newer versions (and in alignment with the XQuery > 3.1 specs and the fn:parse-json function), it is also possible now to > convert JSON data to atomic XQuery items (maps, arrays, strings, > numbers and booleans) [1,2]. The resulting representation will be more > memory-efficient, and access to XQuery maps is blazing fast, but it > won’t be possible to store this representation to a database. > > Hope this helps, greetings, > Christian > > [1] https://urldefense.proofpoint.com/v2/url?u=http-3A__docs. > basex.org_wiki_JSON-5FModule-23XQuery&d=DwIFaQ&c=DS6PUFBBr_ > KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq- > Up2QMq9rrGyfWK0KtSpT7dxRglA&m=gYEI_kXgIHiAXP9cz0NdqkWgkjfpAGxnOd1 > -b8pW3mo&s=_ugHBUSWLu-V4vzcR6jpfcc11M-g6zbiag5lU7COcLA&e= > [2] https://urldefense.proofpoint.com/v2/url?u=http-3A__docs. > basex.org_wiki_JSON-5FModule-23XQuery-5FFormat&d=DwIFaQ&c=DS6PUFBBr_ > KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq- > Up2QMq9rrGyfWK0KtSpT7dxRglA&m=gYEI_kXgIHiAXP9cz0NdqkWgkjfpAGxnOd1 > -b8pW3mo&s=o-pnuPNeYd74pBg0DLEEtwO3r4IKsaC7DPGIo7gxG6c&e= > > > > On Wed, Nov 15, 2017 at 8:30 AM, <m.vankeulen at utwente.nl> wrote: > > Christian, > > > > The JSON Module suggests that JSON objects are represented as > XML-documents > > with a certain structure, not as immutable maps. Is there support in > BaseX > > for json:parse and json:serialize for parsing JSON in textual form > into > > immutable maps and back to JSON in textual form? > > > > Kind regards, > > Maurice van Keulen > > Aside from XQuery and BaseX converting JSON, because JSON is not just > objects, I think there could be a problem with the concept of converting > JSON to maps, also. For example, these JSON documents aren’t map-like: > > 1. true > 2. ["a", "a", "a", "x"] > > Kendall > >
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.