Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Non-string object keys are coerced to string rather than having toJSON called in Map#toJSON #1713

Copy link
Copy link
Open
@icedtoast

Description

@icedtoast
Issue body actions

What happened

Serializing a Map to JSON uses the toString form of the key, rather than the return value of toJSON.

It should behave like the idiom of serializing an ES2015 Map with JSON.stringify([...map]); - where the toJSON return values are used as keys.

How to reproduce

var obj = {
 toString() { return 'hello'; },
 toJSON() { return 'world'; }
};

var m = new ImmutableJS.Map();
m = m.set(obj, 'the value');

JSON.stringify(m); 
/** output is '{"hello":"the value"}' but should be '{"world":"the value"}' **/

JSON.stringify([...m]);
 /** output is '[["world","the value"]]' (correct) **/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.