D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16432 - JSON incorrectly parses to string
Summary: JSON incorrectly parses to string
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, trivial
: 13660 (view as issue list)
Depends on:
Blocks:
 
Reported: 2016-08-26 09:54 UTC by Alex
Modified: 2021-03-22 13:13 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Alex 2016-08-26 09:54:45 UTC
Trying to copy a JSONValue via .toString.parseJSON, see 
https://forum.dlang.org/thread/tsmllrkvdkuskroxcpcc@forum.dlang.org
found an error during conversion to string: 

If a value is a floating type, which ends with a .0 during conversion to string, the part after the point is cut away and the value is interpreted as an integer afterwards. 

void main()
{
    import std.json; 
    import std.stdio; 

    string s = "{\"rating\": 3.0 }";
    JSONValue j = parseJSON(s);
    
    assert(j["rating"].type == JSON_TYPE.FLOAT); 
    
    writeln(j.toString); 
    
    j = j.toString.parseJSON; 
    
    assert(j["rating"].type != JSON_TYPE.FLOAT); 
    assert(j["rating"].type == JSON_TYPE.INTEGER); 
}

If the value is like "3.1" the bug doesn't appear.
Comment 1 Seb 2016-12-30 07:49:48 UTC
pull https://github.com/dlang/phobos/pull/5005
Comment 2 basile-z 2016-12-30 08:48:03 UTC
*** Issue 13660 has been marked as a duplicate of this issue. ***
Comment 3 Dlang Bot 2021-03-18 20:20:26 UTC
@berni44 created dlang/phobos pull request #7885 "Fix Issue 16432 - JSON incorrectly parses to string" fixing this issue:

- Fix Issue 16432 - JSON incorrectly parses to string

https://github.com/dlang/phobos/pull/7885
Comment 4 Dlang Bot 2021-03-22 13:13:31 UTC
dlang/phobos pull request #7885 "Fix Issue 16432 - JSON incorrectly parses to string" was merged into master:

- a99ea1850c3b934f498ac774f550b5e1057e2cae by berni44:
  Fix Issue 16432 - JSON incorrectly parses to string

https://github.com/dlang/phobos/pull/7885