Skip to content
Advertisement

Prevent node.js from converting a nested object with numeric keys into array

When i have an object with a nested object within, whose keys are numbers and send it to my node.js server, then the nested object is converted to an array. How can i prevent this ?

Client:

JavaScript

Server:

JavaScript

{ new: [ ‘Test’, ‘Hello’ ] }

When i add a not numeric key, everything works fine. Also when the keys are at the first level.

My settings:

JavaScript

Advertisement

Answer

Try adding the contentType header and using JSON.stringify to serialize the object before passing to $.ajax:

JavaScript

See jQuery posting JSON.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement