10 examples of 'javascript import json file' in JavaScript

Every line of 'javascript import 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
this disclaimer
16function importJson() {
17 try {
18 return require("./config.json")
19 } catch (ex) {
20 return {}
21 }
22}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

37function importFromJson(json){
38 scope.$parent.paper.clear();
39 // Deserialize from json
40 scope.$parent.paper.fromJSON(json, function (el, data){
41 // Restore properties
42 el.height = data.height;
43 el.width = data.width;
44 el.rotation = data.rotation;
45 el.opacity = data.opacity;
46 el.keepratio = data.keepratio;
47 el.mirror = data.mirror;
48
49 // Restore event handlers
50 if(data.background){
51 scope.$parent.initBackground(el);
52 } else if(data.ft){
53 el.mousedown(scope.$parent.elementMouseDown);
54
55 // Restore freeTransform
56 var ft = scope.$parent.paper.freeTransform(el, {}, function(ft, events) {
57 scope.$parent.setCurrent(ft.subject);
58 scope.$parent.handleFtChanged(ft, events);
59 });
60
61 el.ft = ft;
62 el.ft.attrs = data.ft;
63
64 hElement.setHeight(el, ft.attrs.y);
65 hElement.setWidth(el, ft.attrs.x);
66 hElement.setRotation(el, ft.attrs.rotate);
67 hElement.setKeepRatio(el);
68
69 ft.setOpts({'drag':['self']});
70
71 if(el.type === 'text'){
72 ft.setOpts({distance: scope.$parent.constants.ELEMENT_TEXT_HANDLE_DISTANCE});
73 el.inited = true;
74 }
75
76 ft.handles.y.line.handle=true;
77 ft.handles.x.line.handle=true;
78 ft.handles.x.disc.handle=true;
79 ft.handles.y.disc.handle=true;
80
81 hElement.handles(el);
82 }
83
84 return el;
85 });
86 $timeout(scope.$parent.unfocus, 1);
87}
742value: function importJSON() {
743 var data = this.cache.json.get('data');
744 this.path = this.path.fromJSON(data);
745 this.draw();
746}
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}
140function run_import_all(){
141 if(!importing) return;
142 var list=jQuery('.item:not(.danger,.success)');
143 if(!list.length){
144 jQuery('#button_import_all').button('loading');
145 }else{
146 var id=jQuery('.item:not(.danger,.success1)').attr('id');
147 if(id) item_import(id);
148 }
149}
57async function importFile() {
58 let data = await $drive.open();
59 $file.write({
60 data: data,
61 path: `www/roms/${data.fileName}`
62 });
63 reloadData();
64}
10function importFile(path) {
11 try {
12 const content = fs.readFileSync(path, { encoding: 'utf8' });
13 return JSON.parse(content);
14 } catch (error) {
15 /* eslint-disable no-console */
16 console.error('could not parse ', path, 'as JSON');
17 console.error(error);
18 /* eslint-enable no-console */
19 }
20
21 return null;
22}
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}
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}
123function importData () {
124 var resImp = $('#resImp');
125 resImp.hide();
126
127 try {
128 data = JSON.parse($('#importBox').val());
129 }
130 catch (e) {
131 // TODO: We should create a single message box instead using alert.
132 alert('Error while parsing data in the hereinabove box...');
133 return;
134 }
135
136 // TODO: We should check for all implementation scripts be loaded before trying to parse the input.
137 console.log(data);
138 resImp.empty();
139
140 if (data.mangas) {
141 $('<div class=\'resImpDiv\'><span class=\'resImport\'>' + JSON.parse(data.mangas).length + ' mangas found.</span><div class=\'button\' id=\'btnMangaMerge\'>Import manga list (merge)</div><div class=\'button\' id=\'btnMangaErase\'>Import manga list (erase)</div></div>').appendTo(resImp);
142
143 var importActualMangas = importManga.bind(null, this);
144 $('#btnMangaMerge').on('click', importActualMangas.bind(null, true));
145 $('#btnMangaErase').on('click', importActualMangas.bind(null, false));
146 }
147
148 if (data.bookmarks) {
149 $('<div class=\'resImpDiv\'><span class=\'resImport\'>' + JSON.parse(data.bookmarks).length + ' bookmarks found.</span><div class=\'button\' id=\'btnBookMerge\'>Import bookmark list (merge)</div><div class=\'button\' id=\'btnBookErase\'>Import bookmark list (erase)</div></div>').appendTo(resImp);
150 $('#btnBookMerge').on('click', function () {
151 importBookmark(this, true);
152 });
153
154 $('#btnBookErase').on('click', function () {
155 importBookmark(this, false);
156 });
157 }
158
159 resImp.show();
160}

Related snippets