When the XML has an associated schema, the type information for atomic values
is used to choose the appropriate JSON output.
In this case it appears your schema has a numeric type associated with <price1>
and <price2> so its (correctly) converting to a JSON Numeric type.
" Note that the second one treated the values as integer."
Incorrect, JSON has no "Integer" types. the value JSON { "price2" : 10 }
is the correct representation for the "Number" 10 (or 10.0 or 10.00000000) in
JSON.
If you want a string value you can change your schema so that the values are
strings, change the namespace of your document so that it doesn't match the
schema, pre or post process the data to 'massage' it to the values you want.
I don't know of any way to force a specific # of fractional 0's in a JSON
Number format, nor any JSON parser that would give you a different result if it
did. (it would be a non-conforming parser)
From: [email protected]
[mailto:[email protected]] On Behalf Of Geert Josten
Sent: Tuesday, January 12, 2016 8:45 AM
To: MarkLogic Developer Discussion <[email protected]>
Subject: Re: [MarkLogic Dev General] JSON transformation problem
Hi Soumadri Roy,
MarkLogic merely omitted non-significant decimals in the serialized form of the
JSON, or maybe your browser is actually doing that. The JSON datatype is
Number, which is a double by definition, regardless if the number has a
fraction or not. See also for instance:
http://www.tutorialspoint.com/json/json_data_types.htm
Is this giving you trouble somehow?
Kind regards,
Geert
From:
<[email protected]<mailto:[email protected]>>
on behalf of "Roy Chowdhury, Soumadri"
<[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Date: Tuesday, January 12, 2016 at 1:34 PM
To: "[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] JSON transformation problem
Hi,
I am trying to transform the below mentioned XML data into JSON:
<data>
<price1>10.23</price1>
<price2>10.00</price2>
</data>
When I am executing it against a database which does not have the respective
schema associated I am getting the following output:
{"data":{"price1":"10.23", "price2":"10.00"}}
When I am executing it against a database with proper schema associated, it
returns the following:
{"data":{"price1":10.23, "price2":10}}
Note that the second one treated the values as integer. This is not happening
when the data is returned in XML format.
Why the function is behaving differently in the above two cases and is there a
way to retain two decimal places after dot(.) even when the schema is
associated?
Regards,
Soumadri Roy
"This e-mail and any attachments transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential , proprietary or
privileged information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message. Any
unauthorized review, use, disclosure, dissemination, forwarding, printing or
copying of this e-mail or any action taken in reliance on this e-mail is
strictly prohibited and may be unlawful."
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general