JSON files are a great way of storing data, but WordPress blocks their upload by default. Here's how to allow JSON File Uploads In WordPress.
We ran into this issue when trying to integrate Lotties into our sites, as they come in .JSON format. For security reasons, WordPress will block them from upload. To fix this, we need to add a new MIMEType for JSON, excluding that filetype from the security rules. Once implemented, you can upload a JSON to your WordPress media library, just as you do with images. Self hosting reduces third party requests and speeds up your site.
Install this code using Advanced Scripts or Code Snippets (simply copy paste) and toggle it on. Then just drag and drop your JSON into the media library.
function cc_mime_types($mimes) {
$mimes['json'] = 'application/json';
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
Here's where that code's from: StackOverflow article. This actually allows you to upload both JSON and SVGs.
The is an actual security risk here, so turn it on to upload your files, then toggle it off until you need to add a new JSON to your WordPress site. Also, PLEASE sanitize and scan the files for any issues/malicious elements. JSON security. SVG security.
There's also a Plugin that we've used in the past, which allows you to toggle many different MIME (file) types on your site. If you need a bit more power, check it out: