krammer krammer - 4 months ago 17
JSON Question

Parsing JSON with spaces in key name with AngularJS

I have a json which has spaces in key names.

The JSON has the following format

{
"response":{"docs":[
{
"my name":"krammer",
"job": "stackexchange"
}
}
}


While using ng-repeat to get the parameters into a list, I use the following code

{{friends.['my name']}}


But this gives an empty output. While

friends.my name


gives an error.

So how can the key names with empty spaces be accessed using AngularJS ?

Answer

Please try this

{{friends['my name']}}