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 parse works with type Buffer #44944

Closed
KristianRykkje opened this issue Jul 8, 2021 · 4 comments
Closed

JSON parse works with type Buffer #44944

KristianRykkje opened this issue Jul 8, 2021 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@KristianRykkje
Copy link

lib Update Request

Configuration Check

My compilation target is ES2015 and my lib is the default.

Missing / Incorrect Definition

parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;

Sample Code

const object = JSON.parse(readFileSync("sample.json"));

Documentation Link

https://262.ecma-international.org/5.1/#sec-15.12.2
https://github.com/nodejs/node/blob/c41c09375b217d9daec614edb590147b14ff9b21/lib/buffer.js#L405

Suggestion

parse(text: string | Buffer, reviver?: (this: any, key: string, value: any) => any): any;

@IllusionMH
Copy link
Contributor

Same as #17203 and moreover Buffer is Node specific type and doesn't looks like it belongs to standard lib files.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 8, 2021
@RyanCavanaugh
Copy link
Member

This is just an implicit coercion, not anything JSON.parse does.

@qwelias
Copy link

qwelias commented Dec 2, 2023

This is just an implicit coercion, not anything JSON.parse does.

Literally false, see the spec step 1: Let jsonString be ? ToString(text) which explicitly converts text arg to it's string representation before doing anything else

@RyanCavanaugh
Copy link
Member

I'm curious what you think an implicit coercion is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants