[issue34972] json dump silently converts int keys to string

2020-04-05 Thread Stuart Bishop
Stuart Bishop added the comment: (sorry, my example is normal Python behavior. {1:1, 1.0:2} == {1:2} , {1.0:1} == {1:1} ) -- nosy: +stub ___ Python tracker ___ __

[issue34972] json dump silently converts int keys to string

2020-04-05 Thread Stub
Stub added the comment: Similarly, keys can be lost entirely: >>> json.dumps({1:2, 1.0:3}) '{"1": 3}' -- nosy: +Stub2 ___ Python tracker ___ _

[issue34972] json dump silently converts int keys to string

2020-02-03 Thread Facundo Batista
Facundo Batista added the comment: I understand (and agree with) the merits of automatically converting the int to str when dumping to a string. However, this result really surprised me: >>> json.dumps({1:2, "1":3}) '{"1": 2, "1": 3}' Is it a valid JSON? -- nosy: +facundobatista _

[issue34972] json dump silently converts int keys to string

2018-10-14 Thread Eric V. Smith
Change by Eric V. Smith : -- resolution: -> not a bug ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:

[issue34972] json dump silently converts int keys to string

2018-10-14 Thread My-Tien Nguyen
Change by My-Tien Nguyen : -- status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue34972] json dump silently converts int keys to string

2018-10-14 Thread My-Tien Nguyen
My-Tien Nguyen added the comment: Sure, I can do that, but wanted to propose this regardless. I guess this is a disagreement on a language design level. As a proponent of strong typing I wouldn’t have allowed non-string keys in the first place, and if they are allowed I would warn about conver

[issue34972] json dump silently converts int keys to string

2018-10-13 Thread Steve Dower
Steve Dower added the comment: Agreed with Eric. json.dump needs to produce valid JSON, which requires keys to be strings. Try using pickle if you need to preserve full Python semantics. -- nosy: +steve.dower resolution: -> not a bug stage: -> resolved status: open -> closed _

[issue34972] json dump silently converts int keys to string

2018-10-13 Thread Eric V. Smith
Eric V. Smith added the comment: I can't think of another place where we issue a warning for anything similar. I'm opposed to any changes here: it's clearly documented behavior. It's like being surprised .ini files convert to strings: it's just how that format works. -- nosy: +eric.

[issue34972] json dump silently converts int keys to string

2018-10-13 Thread My-Tien Nguyen
My-Tien Nguyen added the comment: I don’t think, “other languages do that too” is a good argument here. This would apply if behaving differently would break user expectation. But here we would do nothing more than explicitly inform the user of a relevant operation. If they already expected th

[issue34972] json dump silently converts int keys to string

2018-10-13 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks for the report. There was a related issue few days back issue32816. I think this is a documented behavior at https://docs.python.org/3.8/library/json.html#json.dumps . Having a warning in place might break code and I don't know if there is a

[issue34972] json dump silently converts int keys to string

2018-10-13 Thread My-Tien Nguyen
New submission from My-Tien Nguyen : When int keys are silently converted to string on json serialization, the user needs to remember to convert it back to int on loading. I think that a warning should be shown at least. In my case I serialize a dict to json with int keys, later load it back i

[issue34972] json dump silently converts int keys to string

2018-10-13 Thread My-Tien Nguyen
Change by My-Tien Nguyen : -- nosy: My-Tien Nguyen priority: normal severity: normal status: open title: json dump silently converts int keys to string ___ Python tracker ___ _