10 examples of 'curl json file' in JavaScript

Every line of 'curl 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
98async function loadJSON(url) {
99 const req = await fetch(url);
100 return req.json();
101}
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

97function _fetchJson(url){
98 try{
99 var http = WinHTTP(url);
100 if(http.status==200){
101 return JSON.parse(http.responseText);
102 }else if(http.status==500){
103 Mpi.message = "Server error. message from server:'" + http.responseText + "'.";
104 }else{
105 Mpi.message = "Can not load package.server error-" + http.status + ".";
106 }
107 }catch(ex){
108 Mpi.message = ex.description;
109 }
110 return null;
111};
1export function get_json(url, success=null, error=null) {
2 var request = new XMLHttpRequest();
3 request.open("GET", url, true);
4 request.onload = function() {
5 if (request.status >= 200 && request.status < 400) {
6 var data = JSON.parse(request.responseText);
7 if (success !== null) {
8 success(data);
9 }
10 } else {
11 if (error !== null) {
12 error(request);
13 } else {
14 console.log('onload : some error occured');
15 console.log(request);
16 }
17 }
18 };
19 request.onerror = function(){
20 if (error !== null) {
21 error(request);
22 } else {
23 console.log('onerror : some error occured');
24 console.log(request);
25 }
26 };
27 request.send();
28}
112function get_json(url, callback) {
113 $.ajax({
114 url: url,
115 dataType: 'json',
116 success: function(data) {
117 callback(null, data);
118 },
119 error: function(err) {
120 callback('Error getting: ' + url);
121 }
122 });
123}
1export default function fetchJson(url, callback) {
2 const req = new XMLHttpRequest();
3 req.onload = () => {
4 if (req.status >= 200 && req.status < 300) {
5 const text = req.responseText;
6 try {
7 callback(null, JSON.parse(text));
8 } catch (e) {
9 callback(e, null);
10 }
11 } else {
12 callback(new Error(`${req.status}: ${req.statusText}`), null);
13 }
14 };
15 req.onerror = (e) => {
16 callback(e.error, null);
17 };
18 req.open('GET', url, true);
19 req.send(null);
20}
83function fetchJSON(url, callback) {
84 makeRequest(url, jsonHandler(callback));
85}
93export function loadJSON(url: string, callback: Function): void {
94 if (!url.contains("://")) {
95 url = `${window.location.protocol}//${normalizeURL(window.location.host)}/${url}`;
96 }
97 metron.web.get(`${url}`, {}, null, "JSON", function (data: JSON) {
98 if (callback != null) {
99 callback(data);
100 }
101 });
102}
39function fetchJSON(url) {
40 return new Promise((resolve, reject) => {
41 const req = new XMLHttpRequest();
42 req.onload = () => {
43 if (req.status === 200) {
44 try {
45 resolve(JSON.parse(req.response));
46 } catch (err) {
47 reject(`Couldn't parse response. ${err.message}, ${req.response}`);
48 }
49 } else {
50 reject(`Request had an error: ${req.status}`);
51 }
52 };
53 req.onerror = reject;
54 req.onabort = reject;
55 req.open('GET', url);
56 req.send();
57 });
58}
214function fetchJSON_(url, callback) {
215 var xhr = new XMLHttpRequest();
216 xhr.open('GET', url, true);
217 xhr.addEventListener('load', function(e) {
218 if (this.status == 200) {
219 callback(JSON.parse(xhr.responseText));
220 } else {
221 throw "Unable to load manifest.";
222 }
223 });
224 xhr.send();
225}
8export default function fetchJSON(url) {
9 return Observable::fromPromise(fetch(url))
10 ::mergeMap(response => response.json())
11}

Related snippets