SaschaWillems / vulkan.gpuinfo.org

Front-End and Back-End for the Vulkan Hardware Database
https://vulkan.gpuinfo.org
GNU Affero General Public License v3.0
23 stars 4 forks source link

_format_json doesn't properly handle commas inside quotes #26

Closed Kangz closed 4 years ago

Kangz commented 4 years ago

For example https://vulkan.gpuinfo.org/api/v2/devsim/getreport.php?id=8483 contains the following:

            {

                "extension": "VK_KHR_driver_properties",

                "name": "driverInfo",

                "value": "Driver Build: 18049cd,
                         Ie201753318,
                         1582837781\nDate: 02/27/20\nCompiler Version: EV031.29.02.01\nDriver Branch: gfx-adreno.lnx.1.0\n"
                },

Which is invalid JSON produced because the comma always adds a newline, even when inside quotes.

SaschaWillems commented 4 years ago

Thanks for bringing this up. Can you tell me what tool you used to check the validity of that JSON. I tested with VSCode and and online editor, and for both this was valid JSON and neither of them breaks like in the snippet you posted. The JSON Linter at https://jsonlint.com/ also reports this as a valid JSON file.

Kangz commented 4 years ago

I was using the following in Python:

import json
json.loads(the_report)

Looking at the JSON spec, newline aren't allowed in strings but it seems most tools accept it? Feel free to close as won't fix if you want.

SaschaWillems commented 4 years ago

Using e.g. python to consume the API was one of the reasons for writing it, so I'd like to fix this ;)

I just checked with python 3 and it loads fine for me with json.loads and I don't get any new lines in the string.

Are you using python 2?

Kangz commented 4 years ago

Sorry my mistake, I improperly decoded the file. It properly contains "\n" and not newline. Sorry for the noise.