I have a string like this:
string = '{ "key": [
{ "foo": "bar" }
] }';
This string is converted into a JSON object by doing
json = $.parseJSON(string);
and then it looks like this:
{ "key":
{ "0":
{ "foo": "bar" }
}
}
So it seems like the array was converted into a hash.
The desired outcome would instead be:
{ "key": [
{ "foo": "bar" }
] }
What's the best way to achieve this? Background: I am posting JSON data to a URL but need the array to stay intact so the recipient can parse it accordingly.
Update
Here is what I see in a console of Chrome 37.0.2062.120 and jQuery 1.11.1:
It looks like an array, but is really just another hash with a key of "0". Or am I getting something wrong?
Update 2
After converting the string into a JSON update I am posting it to a url:
$.ajax({
url: 'http://test.com',
data: json,
dataType: 'jsonp',
type: 'post'
})
where it arrives as
{ "key":
{ "0":
{ "foo": "bar" }
}
}