I wasn't able to find similar topic in google.
I return simple object into the django template through views
views:
return render(request, 'mainPage.html', {
'obj': getObj()
})
def getObj():
path = '/home/myPage' + 'obj.json'
fd = open( path, 'r')
obj = fd.read()
fd.close()
return json.dumps(obj)
template:
<input type="hidden" id="obj" data-obj="{{ obj }}">
and JS:
var obj = JSON.parse( $('#obj').data('obj') );
console.log( obj );
I see in the console the right result:
{
"2018": {
"First": {
"obj1": "4",
"obj2": "231",
}
}
}
but when I try to refer to this obj by console.log(obj ['2018']); it returns undefined
Will be thankful for your help Thanks in advance