From what I understand the json specification has first calss support for methods/functions.
I have the following json file that I am using as a test fixture.
{
"tokenParsed": {
"preferred_username": "Test User"
},
"hasResourceRole": function () {
return function (role, resource) {
if (role && resource) {
return true
}
}
}
}
If I try to import the file into my VueJS project with
import { keycloak_test_user } from './fixtures/keycloak_test_user.json'
I get the following error
SyntaxError: Unexpected token ( in JSON at position 89
at JSON.parse (<anonymous>)
2 | import Vuex from 'vuex'
3 | import Permission from '@/components/user/Permission.vue'
> 4 | import { keycloak_test_user } from './fixtures/keycloak_test_user.json'
The above json works fine if I add it directly in my test file rather than importing it.
Although, the error says JSON.parse, I am not sure if that is because webpack is not laoding the file correctly or if JSON.parse is a direct cause for the error, however, even VSCode json formatting sees the function as invalid json.