[MarkLogic Dev General] JSON transformation problem

David Lee David.Lee at marklogic.com
Mon Jan 18 09:35:22 PST 2016

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: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Geert Josten
Sent: Tuesday, January 12, 2016 8:45 AM
To: MarkLogic Developer Discussion <general at developer.marklogic.com>
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:


Is this giving you trouble somehow?

Kind regards,

From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of "Roy Chowdhury, Soumadri" <SRRoyChowdhury at INNODATA.COM<mailto:SRRoyChowdhury at INNODATA.COM>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Tuesday, January 12, 2016 at 1:34 PM
To: "general at developer.marklogic.com<mailto:general at developer.marklogic.com>" <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: [MarkLogic Dev General] JSON transformation problem


I am trying to transform the below mentioned XML data into JSON:

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?

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."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20160118/8ec68920/attachment.html 

More information about the General mailing list