Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Parsing Issue (Float field) #3979

Closed
philocalyst opened this issue Jul 25, 2024 · 0 comments
Closed

JSON Parsing Issue (Float field) #3979

philocalyst opened this issue Jul 25, 2024 · 0 comments

Comments

@philocalyst
Copy link

philocalyst commented Jul 25, 2024

Context

    Odin:    dev-2024-07:b4ca044ae
    OS:      macOS Sonoma 14.5 (build: 23F79, kernel: 23.5.0)
    CPU:     Apple M3 Pro
    RAM:     36864 MiB
    Backend: LLVM 18.1.8

Expected Behavior

Just using the Json.unmarshal procedure and I would expect my values to be unmarsheled.

Current Behavior

It throws this error: Unsupported_Type_Error{id = string, token = Token{pos = Pos{offset = 86, line = 1, column = 86}, kind = "Float", text = "98.47800000000001"}}

And then quits.

Steps to Reproduce

Use this JSON:

{
    "data": {
        "submissionDetails": {
            "runtime": 3,
            "runtimeDisplay": "3 ms",
            "runtimePercentile": 98.47800000000001,
            "runtimeDistribution": "{\"lang\": \"cpp\", \"distribution\": [[\"1\", 10.4259], [\"4\", 11.5796], [\"7\", 14.6371], [\"10\", 12.203399999999998], [\"13\", 2.9324000000000003], [\"16\", 1.0469], [\"19\", 0.3913], [\"22\", 0.1465], [\"25\", 0.08679999999999999], [\"28\", 0.0931], [\"31\", 0.10389999999999999], [\"34\", 0.123], [\"37\", 0.2831], [\"40\", 1.3122], [\"43\", 4.7574000000000005], [\"46\", 7.318], [\"49\", 4.3819], [\"52\", 4.4509], [\"55\", 0.4182], [\"58\", 0.22399999999999998], [\"62\", 0.2098], [\"65\", 0.27590000000000003], [\"68\", 0.36619999999999997], [\"71\", 0.3087], [\"74\", 0.2866], [\"77\", 0.3208], [\"80\", 0.3044], [\"83\", 0.2959], [\"86\", 0.4246], [\"89\", 0.5441], [\"92\", 0.6977], [\"95\", 0.5597000000000001], [\"98\", 0.3486], [\"101\", 0.7539], [\"104\", 0.9338], [\"107\", 0.8784000000000001], [\"110\", 0.8841], [\"113\", 0.40190000000000003], [\"116\", 0.6244999999999999], [\"119\", 0.4637], [\"122\", 0.2823], [\"125\", 0.1565], [\"128\", 0.31010000000000004], [\"131\", 0.3983], [\"134\", 0.5890000000000001], [\"137\", 0.41259999999999997], [\"140\", 0.16649999999999998], [\"143\", 0.29719999999999996], [\"146\", 0.4282], [\"149\", 0.3258], [\"152\", 0.2077], [\"155\", 0.0847], [\"158\", 0.16999999999999998], [\"161\", 0.2198], [\"164\", 0.1572], [\"167\", 0.1408], [\"170\", 0.0633], [\"173\", 0.1245], [\"176\", 0.1864], [\"179\", 0.1572], [\"183\", 0.0968], [\"186\", 0.0328], [\"189\", 0.0398], [\"192\", 0.0518], [\"195\", 0.0867], [\"198\", 0.0853], [\"201\", 0.1415], [\"204\", 0.16720000000000002], [\"207\", 0.20980000000000001], [\"210\", 0.1834], [\"213\", 0.0619], [\"216\", 0.0632], [\"219\", 0.1188], [\"222\", 0.1551], [\"225\", 0.1572], [\"228\", 0.1636], [\"231\", 0.17359999999999998], [\"234\", 0.24259999999999998], [\"237\", 0.3833], [\"240\", 0.5626]]}",
            "memory": 14444000,
            "memoryDisplay": "14.4 MB",
            "memoryPercentile": 14.425900000000006,
            "memoryDistribution": "{\"lang\": \"cpp\", \"distribution\": [[\"6700\", 0.0007], [\"6800\", 0.0021], [\"6900\", 0.005], [\"7000\", 0.0036], [\"7100\", 0.0007], [\"10100\", 0.0014], [\"10200\", 0.0036], [\"10300\", 0.0014], [\"10500\", 0.0007], [\"12300\", 0.0057], [\"12400\", 0.5626], [\"12500\", 4.2624], [\"12600\", 14.135], [\"12700\", 14.7353], [\"12800\", 4.1486], [\"12900\", 3.8463], [\"13000\", 4.6131], [\"13100\", 0.5391], [\"13200\", 0.5043], [\"13300\", 0.3542], [\"13400\", 0.3805], [\"13500\", 1.3094], [\"13600\", 3.4246], [\"13700\", 3.3606], [\"13800\", 0.8919], [\"13900\", 1.6053], [\"14000\", 6.8506], [\"14100\", 9.5753], [\"14200\", 5.0995], [\"14300\", 1.6757], [\"14400\", 3.6749], [\"14500\", 0.8926], [\"14600\", 0.6778], [\"14700\", 1.0007], [\"14800\", 0.2717], [\"14900\", 0.7504], [\"15000\", 0.7205], [\"15100\", 0.3101], [\"15200\", 0.2091], [\"15300\", 0.0996], [\"15400\", 0.059], [\"15500\", 0.2674], [\"15600\", 0.9993], [\"15700\", 2.3997]]}",
            "code": "\n\nclass Solution {\npublic:\n  vector<int> twoSum(vector<int> &nums, int target) {\n   unordered_map<int, int> vault;\n    for (int i = 0; i < nums.size(); i++) {\n      int ideal = target - nums[i];\n\n      if (vault.find(ideal) != vault.end()) {\n        return {i, vault[ideal]};\n      }\n      vault[nums[i]] = i;\n    }\n    return {0, 1};\n  }\n};\n",
            "timestamp": 1721875703,
            "statusCode": 10,
            "user": {
                "username": "philocalyst",
                "profile": {
                    "realName": "",
                    "userAvatar": "https://assets.leetcode.com/users/default_avatar.jpg"
                }
            },
            "lang": {
                "name": "cpp",
                "verboseName": "C++"
            },
            "question": {
                "questionId": "1"
            },
            "notes": "",
            "topicTags": [],
            "runtimeError": null,
            "compileError": null,
            "lastTestcase": ""
        }
    }
}

Try to use JSON.Unmarshal.

This is the struct I used when parsing:

GraphQL_Submission_Details :: struct {
    data: struct {
        submissionDetails: struct {
            runtimeDisplay:    string,
            runtimePercentile: string,
            memoryDisplay:     string,
            memoryPercentile:  string,
        },
    },
}
@philocalyst philocalyst closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant