I use datatables.net jQuery plugin to work with ajax tables. I want to send a POST request with JSON data in it. I use JSON.stringify to turn my data into JSON. It produces the result like this:
[
{"name":"sEcho","value":1},
{"name":"iColumns","value":9},
{"name":"sColumns","value":""},
{"name":"iDisplayStart","value":0}
...]
Though I want it to be like this:
{"sEcho":1, "iColumns":9, "sColumns":"", "iDisplayStart":0} ...
How can I do it?
You may iterate over your data and build the desired structure before
JSON.stringify-ing it:You may also save a couple of lines and make it looks a bit nicer using jQuery
eachmethod: