简体   繁体   中英

Extract data from json file

If I have a static json file on my server, is it possible to extract only the required section of the json data using javascript without downloading the whole json file?

I understand that I can use serverside technologies to dynamically generate json data to based on what I want, but I just wanted to know if javascript can be used to extract data from a server json file without downloading the whole thing?

No, you can't do this client side as the browser called by javascript can only fetch a whole file.

If you really need to get only part of the file, you'll have to build server side code.

But check before by profiling that you need to do this optimization. And don't forget that fetching only part of a file would prevent the file from being cached and reused as a whole.

For a static file on the server, how would JavaScript access it without downloading the whole file?

I'm afraid this is impossible. You could download the file and filter through the data on the client, or you could write server-side code to do the filtering for you, then output the result to the caller -- your client-side JavaScript code.

the answer is no, but if you could handle the json data on server side, you could create a json response when sending parameters on your ajax call to retrieve different results depending on the parameters you sent. These parameters would limit which sections you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM