You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Jason Smith (Commented) (JIRA)" <ji...@apache.org> on 2012/02/11 16:19:59 UTC

[jira] [Commented] (COUCHDB-1407) JSON encoding of number changes

    [ https://issues.apache.org/jira/browse/COUCHDB-1407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13206147#comment-13206147 ] 

Jason Smith commented on COUCHDB-1407:
--------------------------------------

As far as this ticket indicates, CouchDB is neither losing precision nor altering the numeric value. It is changing the representation. Thus this is not a bug in CouchDB.

This ticket's opening sentence makes an inaccurate assumption. JSON does not encode "Numbers" (upper-case), like the data type in Javascript. JSON encodes "numbers" (lower-case), what sensible people call real numbers. AFAIK the spec makes no assumptions about how you deserialize and represent that value in your hardware and language.

In other words, just as 1.0 = 1 in arithmetic, {"a":1} and {"a":1.0} encode the same thing in JSON. If the numeric type is important to you, then store that in the doc. (More often, you'll just type cast.) Or maybe your JSON decoder has an option to disable DWIMming the type.

Consider:

1. What if Couch had returned {"a":"1.00}? Would that be a bug? Why not? No fair saying 1.00 is the same type as 1.0 because JSON has no types, only a syntax.

2. Is it a bug if Couch encodes strings greater than 32,767 characters long, the maximum string length in QuickBasic, beyond which there is a runtime error?
                
> JSON encoding of number changes
> -------------------------------
>
>                 Key: COUCHDB-1407
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1407
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface
>    Affects Versions: 1.2
>         Environment: Ubuntu 12.04 (alpha)
>            Reporter: Adam Lofts
>
> JSON encoding of Number has changed from 1.0.2 to 1.2. JSON only defines Number but this change causes issues in my app because python decodes the number as an int in 1.2.
> Test case:
> PORT=5985
> curl -X DELETE http://localhost:$PORT/test-floats/
> curl -X PUT http://localhost:$PORT/test-floats/
> curl -X PUT http://localhost:$PORT/test-floats/doc1 -H "Content-Type: application/json" -d "{ \"a\": 1.0 }"
> curl http://localhost:$PORT/test-floats/doc1
> Run against 1.0.2:
> {"ok":true}
> {"ok":true}
> {"ok":true,"id":"doc1","rev":"1-78e61304147429d3d500aee7806fd26d"}
> {"_id":"doc1","_rev":"1-78e61304147429d3d500aee7806fd26d","a":1.0}
> Run against 1.2:
> {"ok":true}
> {"ok":true}
> {"ok":true,"id":"doc1","rev":"1-78e61304147429d3d500aee7806fd26d"}
> {"_id":"doc1","_rev":"1-78e61304147429d3d500aee7806fd26d","a":1}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira