How to read JSON file with Dojo

Damir picture Damir · Mar 15, 2011 · Viewed 15.8k times · Source

How to read JSOn files with Dojo ?

Answer

voidstate picture voidstate · Oct 21, 2012

In Dojo 1.8+, to load a JSON file (not as XHR), use dojo/text to load the file, then dojo/json to parse it. Like so:

require( [ 'dojo/json', 'dojo/text!/path/to/data.json' ], 
    function( JSON, data )
{
    var data = JSON.parse( data );
} );

Not the "!" after dojo/text, used to specify the file to load.