My code looks a little like this:
var data = $(this).serializeArray(data);
$.ajax({
data: JSON.stringify(data)
});
I run a console.log as well and I see the JSON string formatted as:
[{"name":"inputName", "value":"inputValue"}]
Whereas I’m expecting:
[{"inputName":"inputValue"}]
Am I misunderstanding JSON formatting or is there a way to get this to format properly?
JSON (well, any hash/dict) is formatted as
{ property : value }(or{ key : value }). If you want each of thevaluewell…values! in an array, you can do so with a simplefor..instatement.But to directly your answer, you will never see
[{"inputName":"inputValue"}]becauseinputNameis not a key, but a variable (just likeinputValue)