0

I have a myjson.json that looks like this

{
  "main.css": "main-4zgjrhtr.css",
  "main.js": "main-76gfhdgsj.js"
  "normalkey" : "somevalue"
}

The usecase is that I map revision builds to an original filename. Now I want to access the key in javascript. If I do this:

var myjson = require('./myjson.json')

require is so fancy that it sees the '.json' and parses the json for me into an object so

console.log(myjson.normalkey)

returns 'somevalue'. However

console.log(myjson.main.js)

must fail.

So my question is: How does require work with the dot in the keyname?

philkunz
  • 421
  • 2
  • 5
  • 16
  • possible duplicate of [JavaScript property access: dot notation vs. brackets?](http://stackoverflow.com/questions/4968406/javascript-property-access-dot-notation-vs-brackets) – Scimonster Aug 02 '15 at 17:00

1 Answers1

3
console.log(myjson["main.js"]);

should work for you.

ChrisF
  • 134,786
  • 31
  • 255
  • 325