First of all, make sure Apache deflate module is enabled on your system. The below command will enable the deflate module for in Apache on Debian based systems. This tutorial has been tested on Ubuntu 18.04.
sudo a2enmod deflate
Then edit the module configuration file in your favorite text editor.
sudo vim /etc/apache2/mods-enabled/deflate.conf
Then add “AddOutputFilterByType DEFLATE application/json” in the deflate module configuration file.
Save your file and restart Apache2 service to apply new settings.
systemctl restart apache2.service