Thanks to visit codestin.com
Credit goes to github.com

Skip to content

In lists with numerical keys, the condition that @id comes before @ref might fail #20

@lucash

Description

@lucash

This somehow is a follow-up to issue #18, in my case real issues occur due to the browser changing the order of the object elements.

The following code shows the problem in my current version of Chrome (59.0.3071.115) as well as in Firefox (53.0.3):
JSOG.parse('{"a": {"@ref": 0}, "11": {"@id": 0}, "3": {"@ref": 0}, "2": {"@ref": 0}}')
This results in:
Object {2: undefined, 3: undefined, 11: Object, a: Object}

Inspecting the issue I found out that objects which use numbers as keys are sorted in the numerical order of the keys, at least when using JSON.parse:
JSON.parse('{"a": {"@ref": 0}, "11": {"@id": 0}, "3": {"@ref": 0}, "2": {"@ref": 0}}')
Will result in:
Object {2: Object, 3: Object, 11: Object, a: Object}

Am I using JSOG in any wrong way or is this really an issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions