-
Notifications
You must be signed in to change notification settings - Fork 250
Open
Description
e.g.:
print(JSON.stringify([], undefined, 2)) // should be []
print(JSON.stringify({}, undefined, 2)) // should be {}Spec:
- https://tc39.es/ecma262/multipage/structured-data.html#sec-json.stringify
- https://tc39.es/ecma262/multipage/structured-data.html#sec-serializejsonproperty
- https://tc39.es/ecma262/multipage/structured-data.html#sec-serializejsonarray
- https://tc39.es/ecma262/multipage/structured-data.html#sec-serializejsonobject
- If partial is empty, then
a. Let final be "[]".
This happens regardless of state.[[Gap]] (and state.[[Indent]]) which affects only step 10. "Else".
- If partial is empty, then
a. Let final be "{}".
This also happens regardless of state.[[Gap]] (and state.[[Indent]]) which affects only only step 10. "Else" and elements in step 8 (of which there are none here).
I encountered this in snapshot testing with node:test-compatible plain JSON.stringify serialization (as opposed to Jest serializers)
Another place where this could be important is e.g. id generation, if smth does hash(JSON.srtringify(obj)) as a relatively common pattern. If those ids are expected to equal between client and server but aren't, things could break.
That said, that scenario is relatively unlikely to be using padding.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels