10 examples of 'javascript read local json file' in JavaScript

Every line of 'javascript read local json file' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
629function read_json_file(fname) {
630 try {
631 var txt = fs.readFileSync(fname, 'utf8');
632 return JSON.parse(txt);
633 } catch (err) {
634 return null;
635 }
636}
27function readJsons() {
28 function jsonIfExists(file) {
29 if (!utl.existsSync(file)) return null;
30
31 var json = fs.readFileSync(file, 'utf8')
32 , metadata = JSON.parse(json)
33 ;
34
35 metadata.created = utl.stringToDate(metadata.created);
36 metadata.updated = utl.stringToDate(metadata.updated);
37
38 return metadata;
39 }
40
41 blogjson = jsonIfExists(blogjsonFile);
42 postunojson = jsonIfExists(postunojsonFile);
43 postdosjson = jsonIfExists(postdosjsonFile);
44
45}
37function loadJson(filename) {
38 return JSON.parse(fs.readFileSync(filename).toString());
39}
4function loadJSON(filePath) {
5 // Load json file;
6 var json = loadTextFileAjaxSync(filePath, "application/json");
7 // Parse json
8 return JSON.parse(json);
9}
31function readFile(filename, json) {
32 const file = fs.readFileSync(filename, 'utf8');
33 return json ? JSON.parse(file) : file;
34}
48function JSON (file, callback) {
49 fileUtils.read(file, function (contents) {
50 if (!JSHINT(contents)) {
51 var out = JSHINT.data(),
52 errors = out.errors;
53 callback(errors);
54
55 } else {
56 callback(null);
57 }
58 });
59}
9function loadJSON(callback) {
10
11 var xobj = new XMLHttpRequest();
12 xobj.overrideMimeType("application/json");
13 xobj.open('GET', 'sample_data_lwm_3d.json', true);
14 xobj.onreadystatechange = function () {
15 // When response is ready
16 if (xobj.readyState == 4 && xobj.status == 200) {
17
18 // .open will NOT return a value but simply returns undefined in async mode so use a callback
19 callback(xobj.responseText);
20
21 }
22 }
23 xobj.send(null);
24}
41function loadJson(file, jsonId)
42{
43 if ( ! file ) return;
44 $('#jsonFile').val('');
45 var reader = new FileReader();
46 reader.onload = function(e) {
47 doLoadJson(e.target.result, jsonId);
48 };
49 reader.readAsText(file);
50}
12function loadJSON(path, callback) {
13 var request = new XMLHttpRequest();
14 request.overrideMimeType("application/json");
15 request.open('GET', '' + path, true);
16 request.onreadystatechange = function () {
17 if (request.readyState == 4 && (request.status == "200" || request.status == 0)) {
18 callback(JSON.parse(request.responseText));
19 }
20 };
21 request.send(null);
22}
81readFromLocalJson(localUrl){
82 return this.http.get(localUrl, this.requestOpts)
83 .toPromise()
84 .then(res => res.json())
85 .catch(this.handleError);
86}

Related snippets