How to read json file using javascript

How to read json file in javascript using javascript policy?

json file is in resources folder

Solved Solved
1 2 1,077
1 ACCEPTED SOLUTION

You cannot do that.

There's a feature request pending that will allow it, in the future. (ref: b/155436526)

But for now, you cannot.

The way I do it is

  1. code the json file as JavaScript. (include var x = {jsonhere})
  2. use the IncludeURL element in the JS policy
  3. Then the JS in ResourceURL will be able to read what you have assigned to x.

I know, it's not as easy as using json. But that's what we have today.

Another option is to store the JSON file into a KVM , and use KVM Get and then JSON.parse().

View solution in original post

2 REPLIES 2

You cannot do that.

There's a feature request pending that will allow it, in the future. (ref: b/155436526)

But for now, you cannot.

The way I do it is

  1. code the json file as JavaScript. (include var x = {jsonhere})
  2. use the IncludeURL element in the JS policy
  3. Then the JS in ResourceURL will be able to read what you have assigned to x.

I know, it's not as easy as using json. But that's what we have today.

Another option is to store the JSON file into a KVM , and use KVM Get and then JSON.parse().

Thank you sir.