Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularJS - Accessing JSON keys that have spaces in them

enter image description here

Above is a picture of the JSON data being returned by the API. As you can see some of the JSON keys have two words with a space in between them. How can I access that in my angular app. This is coming in as an array BTW.

I have tried:

<li ng-repeat="task in mainTask.Tasks"> {{ task.['CAR ID'] }} </li>

with no luck. Thanks for any help.

like image 584
agon024 Avatar asked Jul 25 '16 20:07

agon024


People also ask

Are spaces allowed in JSON keys?

Whitespace (Space, Horizontal tab, Line feed or New line or Carriage return) does not matter in JSON. It can also be minified with no affect to the data. Object literal names MUST be lowercase (ie – null, false, true etc). Keep all name and value pairs in quotes to aviod.

Can JSON file name have spaces?

JSON conventions¶ Format JSON files to be human readable. Use four spaces for indentation (matching OpenStack conventions used in Python and shell scripts). Do not use tab characters in the code, always use spaces. Use one space after the name-separator (colon).

Can JSON keys be int?

JSON only supports several types of objects as item keys, which are str , int , float , bool and None .


1 Answers

You don't need the dot to access the value. Try:

{{ task['CAR ID'] }}
like image 88
Daniel Waghorn Avatar answered Sep 28 '22 06:09

Daniel Waghorn