The JSON module supported by Chrome 91 simplifies the process of obtaining JSON data for us. This ECMAScript proposal makes importing JSON data as concise and clear as importing ES modules. Just add assert {type: 'json'}
at the end of the import statement.
import configData from './config-data.json' assert {type: 'json'};
This is undoubtedly a big improvement! Looking back, due to the cross-browser compatibility issue of XMLHttpRequest, we had to rely on the Ajax library to get JSON data; later, although the fetch API simplified the process, it still needed to write code. Now, you can import JSON data in just one line of code (for simple JSON data).
Getting JSON data directly through a line of code is the convenient way we have been looking forward to for a long time. In addition, URLs can now be set dynamically, making them more flexible.
The above is the detailed content of ECMAScript proposal: JSON modules. For more information, please follow other related articles on the PHP Chinese website!