2

I have a JSON file

Testing.json

{
  "DEV_MODE": false
}

and how can I access this value in JavaScript because i want to make check

if( DEV_MODE === true) {...} else {...}

I tried like this

import jsonFile from '../../testing.json'
var json = JSON.parse(jsonFile)
if(json.getProperty('DEV_MODE'){
...
}else{
...
}

but it doesn't work.

1
  • 1
    if(json["DEV_MODE"]) {... Commented Sep 11, 2018 at 13:10

2 Answers 2

4

You should be able to access the DEV_MODE property like this:

json.DEV_MODE or json["DEV_MODE"]

Sign up to request clarification or add additional context in comments.

Comments

1

You can access to your json file easily and you don't need to parse that, like the following:

import jsonFile from '../../testing.json'
if (jsonFile.DEV_MODE) {
  ...
} else {
  ...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.