How To Allow JSON File Uploads In WordPress

By James LePage
 on December 22, 2020
Last modified on January 6th, 2022

How To Allow JSON File Uploads In WordPress

By James LePage
 on December 22, 2020
Last modified on January 6th, 2022

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.

Saving JSON responses to your model in Scala

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');Code language: PHP (php)

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:

Subscribe & Share
If you liked this content, subscribe for our monthly roundup of WordPress news, website inspiration, exclusive deals and interesting articles.
Unsubscribe at any time. We do not spam and will never sell or share your email.
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
3 years ago

Thanks a lot James! Didn't seem to work for me though, added your code via code snippets, and still not going through. Could it be on the server side? I'm hosted via vultr on Cloudways..

Also by the way, great commenting interface.. what plugin are you using for commenting?

Last edited 3 years ago by Solomon
3 years ago

Thanks for this, very helpful!

2 years ago

How to add this code? As a java script file? But not working for me

9 months ago

Thanks for the code. it help upload the file, even when I enable json file with Elementor it didn't work without the code

Article By
James LePage
James LePage is the founder of Isotropic, a WordPress education company and digital agency. He is also the founder of, a venture backed startup bringing AI to WordPress creators.
We're looking for new authors. Explore Isotropic Jobs.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram