2

I have an external JSON file that I need to parse, but it gives errors on any field that contains dashes, e.g.

eventdate: item["event-metadata"].event-date-time

I have no control over this external feed. I tried .["event-date-time"] and ."event-date-time", and .'event-date-time' but these resulted in "unexpected token"

How do I reference these items?

BTW, this is in Meteor.js on a server side.

Florida G.
  • 269
  • 3
  • 11

1 Answers1

4

Don't use dot notation when dashes and other unsupported characters are present. Using dashes in a variable name is invalid for dot notation, so you must index into the object using bracket notation with the string acting as the key and wrapped in quotes:

item["event-metadata"]["event-date-time"]
Brett McLain
  • 2,000
  • 2
  • 14
  • 32