1

I'm trying to make a table out of some JSON data in NodeJS/Jade. The table works fine, except that I can't figure out how to reference object keys which contain spaces.

tbody
    each row in thing
        tr
            td
                !{row.id} //Works fine
            td
                !{row.["some key"]} //causes the renderer to crash

Doing this causes jade to throw a SyntaxError for an unexpected token, so what is the proper way to reference this key?

  • 1
    Possible duplicate of [Accessing JSON object keys having spaces](http://stackoverflow.com/questions/10311361/accessing-json-object-keys-having-spaces) – litel Sep 28 '16 at 17:53
  • Not a duplicate, this is specifically for Jade, not just JavaScript. The normal JS solutions do not work for Jade. – user2809516 Sep 29 '16 at 15:20
  • 1
    Jade's interpolation syntax interprets normal JS. Just apply the advice of that question within the Jade interpolation syntax ` !{row['some key']} ` without the period and your code should work as long as there is a matching key. – litel Sep 29 '16 at 16:47

1 Answers1

2

From the comment by litel, you need to remove the leading period from the property reference.

This line:

row.["some key"]

should be changed to:

row["some key"]
Graham
  • 7,431
  • 18
  • 59
  • 84