HaxeFoundation / HaxeFoundation/haxe

Compiler flag haxeJSON does not work for Python

Open
#9,203 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Hello,

First of all, thanks for all your work! I really like it.

Issue:
Today I tried to enable flag `haxeJSON`, but it seems to do nothing on Python. The compiled code still uses a native implementation of JSON.parse.

Some description and thoughts:
We are developing a product that works a lot with JSON data from 3rd parties.
We use for such purposes Java, JS, and Python.

Recently I stumbled upon an issue with parsing a JSON(-like) data. It contained `NaN` value, which is not valid JSON: `{"a": NaN}`
As I dag deeper, I found out that many languages provide some ways with dealing with such values:
- Python parses and stringifies NaNs in JSON just fine by default. But there are also additional flags to change this behavior: `json.dump(allow_nan=True)` and `json.load(parse_constant=None)`
https://docs.python.org/3/library/json.html

- Java Gson library provides a way of dealing with NaNs by using `serializeSpecialFloatingPointValues` method of `GsonBuilder`.

- JavaScript converts NaNs into `null` when stringifying, but throws an error when parsing data like `{"a": NaN}`

Even if this issue is resolved, it does not actually solve my problem 😞
As far as I can see, native Haxe JSON implementation does not provide a way to override the parsing behavior of some specific values.

My proposal is to add an optional parameter to haxe.JSON.parse, same as `replacer` paremeter of `haxe.JSON.stringify`, but with the opposite behavior 😃
This way I would be able to catch `NaN` in my data and handle it.
https://api.haxe.org/haxe/Json.html#stringify

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.