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

Failed to parse JSON file. #8611

Closed
7 tasks done
zhenzhenChange opened this issue Jun 16, 2022 · 6 comments · Fixed by #8628
Closed
7 tasks done

Failed to parse JSON file. #8611

zhenzhenChange opened this issue Jun 16, 2022 · 6 comments · Fixed by #8628
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@zhenzhenChange
Copy link
Contributor

Describe the bug

parse json fail

Reproduction

https://github.com/zhenzhenChange/vite-parse-json-fail.git

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (6) x64 Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz
    Memory: 6.55 GB / 15.86 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (102.0.1245.41)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-react: ^1.3.0 => 1.3.2
    vite: ^2.9.9 => 2.9.12

Used Package Manager

pnpm

Logs

Just run the project

Validations

@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Jun 16, 2022
@sapphi-red
Copy link
Member

This was because src/city.json starts with a BOM.
For a workaround, you could save it with UTF-8 (without BOM).

@zhenzhenChange
Copy link
Contributor Author

image

Wow, yes indeed, I downloaded this file from the internet and at first I thought it was a failure to parse due to the huge amount of data (4w data at first).

I created a new .json file and the problem was solved.

But this BOM tagging issue should be manageable, right? I checked the information, we are able to remove the BOM marker by logical judgment. But I'm not sure if there will be other similar cases?

@zhenzhenChange
Copy link
Contributor Author

Or force conversion of the file's encoding format before parsing? But that doesn't seem to be a good solution.

@sapphi-red
Copy link
Member

Yes I can be handled like #3171.

@zhenzhenChange
Copy link
Contributor Author

Wow, ok, thank you, I can do this job and launch a pr right after work.

@zhenzhenChange
Copy link
Contributor Author

zhenzhenChange commented Jun 16, 2022

By the way, the logic extraction in #3171 is used as a general method.

@sapphi-red sapphi-red linked a pull request Jun 17, 2022 that will close this issue
9 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants