Console/Command/SerializeToJson.php
protected function execute(InputInterface $input, OutputInterface $output) // @codingStandardsIgnoreLine - required by parent class
    {

        $configPaths = [
            'geoip_country_mapping' => \Fastly\Cdn\Model\Config::XML_FASTLY_GEOIP_COUNTRY_MAPPING
        ];

        foreach ($configPaths as $path) {
            $magVer = $this->productMetadata->getVersion();
            if (version_compare($magVer, '2.2', '<')) {
                $output->writeln(
                    'Warning : This function is used for converting serialized data to JSON'
                        . ' (recommended for Magento versions above 2.2)'
                );
            }

            $oldData = $this->scopeConfig->getValue($path);

            try {
                $oldData = unserialize($oldData); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
            } catch (\Exception $e) {
                $oldData = false;
            }

            if ($oldData === false) {
                $output->writeln(
                    'Invalid serialization format, unable to unserialize config data : ' . $path
                );

                return;
            }
            $oldData = (is_array($oldData)) ? $oldData : [];

            $newData = json_encode($oldData);
            if (false === $newData) {
                throw new \InvalidArgumentException('Unable to encode data.');
            }

            $this->configWriter->save($path, $newData); // @codingStandardsIgnoreLine - currently best way to resolve this
            $this->cacheManager->clean([\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER]);

            $output->writeln('Config Cache Flushed');
        }
    }
protected function execute(InputInterface $input, OutputInterface $output) // @codingStandardsIgnoreLine - required by parent class
    {

        $configPaths = [
            'geoip_country_mapping' => \Fastly\Cdn\Model\Config::XML_FASTLY_GEOIP_COUNTRY_MAPPING
        ];

        foreach ($configPaths as $path) {
            $magVer = $this->productMetadata->getVersion();
            if (version_compare($magVer, '2.2', '<')) {
                $output->writeln(
                    'Warning : This function is used for converting serialized data to JSON'
                        . ' (recommended for Magento versions above 2.2)'
                );
            }

            $oldData = $this->scopeConfig->getValue($path);

            try {
                $oldData = unserialize($oldData); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
            } catch (\Exception $e) {
                $oldData = false;
            }

            if ($oldData === false) {
                $output->writeln(
                    'Invalid serialization format, unable to unserialize config data : ' . $path
                );

                return;
            }
            $oldData = (is_array($oldData)) ? $oldData : [];

            $newData = json_encode($oldData);
            if (false === $newData) {
                throw new \InvalidArgumentException('Unable to encode data.');
            }

            $this->configWriter->save($path, $newData); // @codingStandardsIgnoreLine - currently best way to resolve this
            $this->cacheManager->clean([\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER]);

            $output->writeln('Config Cache Flushed');
        }
    }
Converts Fastly serialized data to JSON format

@param InputInterface $input
@param OutputInterface $output
@return int|null|void