Issue preserving namespaces with json:parse
Friday, 24 November 2017 · 4 messages
CG
Run…
let $opt := map { "lax": true() }
return json:parse('{ "coords":{
"gml:Point":{
"gml:coordinates":"0,0"
} } }', $opt )/json/coords/*…and I’m pretty sure you’ll see what is wrong if you compare the result with the examples in the documentation
(http://docs.basex.org/wiki/Geo_Module#geo:distance).
Quoted text · E. Wray Johnson · 18 lines
On Fri, Nov 24, 2017 at 5:31 PM, E. Wray Johnson <wray.johnson at gmail.com> wrote: > What is wrong with this code? > > import module namespace geo = 'http://expath.org/ns/geo'; > declare namespace gml='http://www.opengis.net/gml'; > > let $opt := map { "lax": true() } > let $y := json:parse('{ "coords":{ > "gml:Point":{ > "gml:coordinates":"0,0" > } } }', $opt ) > > let $x := json:parse('{ "coords":{ > "gml:Point":{ > "gml:coordinates":"-123.45,45.343" > } } }', $opt ) > > return geo:distance($x/json/coords/*, $y/json/coords/*)
CG
Quoted text · E. Wray Johnson · 1 line
> Why does this code work
Because you don’t send the result to the Geo Module.
JSON and XML are different data formats with different semantics. For example, JSON provides no support for namespaces. This is why colons in the JSON key will not be interpreted as namespace delimiters. See the following valid example:
json:parse('{ ":::": "a" }')It would raise errors if we always assumed that strings before colons are to be interpreted as namespace prefixes.
If you want to process JSON data as valid GEO data, you’ll need to post-process your parsed input, e.g. via XQuery Update.
Quoted text · E. Wray Johnson · 61 lines
On Fri, Nov 24, 2017 at 6:15 PM, E. Wray Johnson <wray.johnson at gmail.com> wrote: > >> declare namespace gml="http://www.opengis.net/gml"; >> import module namespace geo = "http://expath.org/ns/geo"; >> declare option output:method 'json'; >> let $x := >> element json { attribute type {'object'}, >> element coords {attribute type {'object'}, >> element gml:Point {attribute type {'object'}, >> element gml:coordinates { "0,0" } >> } >> } >> } >> let $y := json:serialize($x) >> return json:parse($y) > > > I tried without success, adding declare option output:method 'json'; > > > > > > On Fri, Nov 24, 2017 at 11:45 AM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Run… >> >> let $opt := map { "lax": true() } >> return json:parse('{ "coords":{ >> "gml:Point":{ >> "gml:coordinates":"0,0" >> } } }', $opt )/json/coords/* >> >> …and I’m pretty sure you’ll see what is wrong if you compare the >> result with the examples in the documentation >> (http://docs.basex.org/wiki/Geo_Module#geo:distance). >> >> >> >> On Fri, Nov 24, 2017 at 5:31 PM, E. Wray Johnson <wray.johnson at gmail.com> >> wrote: >> > What is wrong with this code? >> > >> > import module namespace geo = 'http://expath.org/ns/geo'; >> > declare namespace gml='http://www.opengis.net/gml'; >> > >> > let $opt := map { "lax": true() } >> > let $y := json:parse('{ "coords":{ >> > "gml:Point":{ >> > "gml:coordinates":"0,0" >> > } } }', $opt ) >> > >> > let $x := json:parse('{ "coords":{ >> > "gml:Point":{ >> > "gml:coordinates":"-123.45,45.343" >> > } } }', $opt ) >> > >> > return geo:distance($x/json/coords/*, $y/json/coords/*) > >
EJ
E. Wray Johnson24 Nov 2017 18:32 #
What is wrong with this code?
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml='http://www.opengis.net/gml';
let $opt := map { "lax": true() }
let $y := json:parse('{ "coords":{
"gml:Point":{
"gml:coordinates":"0,0"
} } }', $opt )
let $x := json:parse('{ "coords":{
"gml:Point":{
"gml:coordinates":"-123.45,45.343"
} } }', $opt )return geo:distance($x/json/coords/*, $y/json/coords/*)
EJ
I already knew what was wrong.
I am looking/hoping for a solution.
Why does this code work and my earlier code not work?
Quoted text · Christian Grün · 14 lines
declare namespace gml="http://www.opengis.net/gml"; > import module namespace geo = "http://expath.org/ns/geo"; > declare option output:method 'json'; > let $x := > element json { attribute type {'object'}, > element coords {attribute type {'object'}, > element gml:Point {attribute type {'object'}, > element gml:coordinates { "0,0" } > } > } > } > let $y := json:serialize($x) > return json:parse($y) >
I tried without success, adding declare option output:method 'json';
Quoted text · Christian Grün · 36 lines
On Fri, Nov 24, 2017 at 11:45 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Run… > > let $opt := map { "lax": true() } > return json:parse('{ "coords":{ > "gml:Point":{ > "gml:coordinates":"0,0" > } } }', $opt )/json/coords/* > > …and I’m pretty sure you’ll see what is wrong if you compare the > result with the examples in the documentation > (http://docs.basex.org/wiki/Geo_Module#geo:distance). > > > > On Fri, Nov 24, 2017 at 5:31 PM, E. Wray Johnson <wray.johnson at gmail.com> > wrote: > > What is wrong with this code? > > > > import module namespace geo = 'http://expath.org/ns/geo'; > > declare namespace gml='http://www.opengis.net/gml'; > > > > let $opt := map { "lax": true() } > > let $y := json:parse('{ "coords":{ > > "gml:Point":{ > > "gml:coordinates":"0,0" > > } } }', $opt ) > > > > let $x := json:parse('{ "coords":{ > > "gml:Point":{ > > "gml:coordinates":"-123.45,45.343" > > } } }', $opt ) > > > > return geo:distance($x/json/coords/*, $y/json/coords/*) >
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery