Save JSON content to file

@param string | array $path
@param string $data
@param  integer $flags
@param  resource  $context

@return bool
324039
public function putContentsJson($path, $data)
    {
        if (!Utils\Json::isJSON($data)) {
            $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        return $this->putContents($path, $data, LOCK_EX);
    }
86387
protected static function saveJson( $fileName, $data )
	{
		$json	= array();
		foreach( $data as $sectionName => $sectionData )
		{
			foreach( $sectionData as $pair )
			{
				$key	= $pair['key'];
				unset( $pair['key'] );
				$json[$sectionName][$key]	= $pair;
			}
		}
		$json	= ADT_JSON_Formater::format( $json, TRUE );
		return FS_File_Writer::save( $fileName, $json );
	}
869461
public static function vue($path, array $data = null)
		{
			$path   = \View::getFinder()->find($path);
			$str    = file_get_contents($path);
			if($data)
			{
				$tag1 = '<scr'.'ipt>';
				$tag2 = '</scr'.'ipt>';
				$json = json_encode($data);
				$str = str_replace($tag1, $tag1 . "(function () {\n\tvar \$data = $json;", $str);
				$str = str_replace($tag2, '}())' . $tag2, $str);
			}
			return $str;
		}
1127262
def write_json_to_file(path, data):
    
    with open(path, 'w', encoding='utf-8') as f:
        json.dump(data, f)
980373
public function create($path, array $data)
    {
        $data = array_merge($data, ['path' => $path]);

        return File::create($data);
    }
749002
public function save($path = self::DEFAULT_FILENAME)
	{
		$file = new File($path);

		$file->write(json_encode($this->data));

		return $this;
	}
1214503
protected static function convertFiles($data, $files, $path = '')
    {
        foreach ($files as $key => $file) {
            $newPath = $path;
            if ($newPath === '') {
                $newPath = $key;
            }
            if ($newPath !== $key) {
                $newPath .= '.' . $key;
            }

            if (is_array($file)) {
                $data = static::convertFiles($data, $file, $newPath);
            } else {
                $data = Hash::insert($data, $newPath, static::convertFile($file));
            }
        }

        return $data;
    }
1101741
public static function write($path, $content = null, $flags = null)
    {
        $path = Normalize::diskFullPath($path);

        $pathArray = explode(DIRECTORY_SEPARATOR, $path);
        array_pop($pathArray);
        $pathName = implode(DIRECTORY_SEPARATOR, $pathArray);

        if (!Directory::exist($pathName)) {
            Directory::create($pathName);
        }
        return @file_put_contents($path, $content, $flags);
    }
637209
public function put($path = null, $data = [], array $options = []) {
		return $this->send(__FUNCTION__, $path, $data, $options);
	}
1323657
protected function write_data(string $path, string $data) {
        $targetpath = $this->path . DIRECTORY_SEPARATOR . $path;
        check_dir_exists(dirname($targetpath), true, true);
        if (file_put_contents($targetpath, $data) === false) {
            throw new \moodle_exception('cannotsavefile', 'error', '', $targetpath);
        }
        $this->files[$path] = $targetpath;
    }
813751
private function setFilePathCollection($path, array $data)
    {
        $key = \array_flip($this->filePathMapping)[$path];

        $this->filePathCollection[$key] = $data;
    }
514919
public function save($path, $format = Document::XML)
    {
        switch ($format) {
            case Document::XML:
                $format = 'saveXML';
                break;
            case Document::HTML:
                $format = 'saveHTML';
                break;
            case Document::JSON:
                $format = 'toJson';
                break;
            default:
                throw new DomException('Invalid format', 2);
        }

        $tmp = Storage::temp($this->$format(), 'tmp', '~xml-');

        if ($tmp === false) {
            throw new DomException('Can\'t create tmp file', 2);
        } elseif (copy($tmp, $path) === false) {
            throw new DomException('Can\'t copy tmp file to ' . $path, 2);
        } else {
            unlink($tmp);
        }
    }
793662
public function postJson($path, $postBody = null, array $parameters = [], $headers = [])
    {
        if (is_array($postBody)) {
            $postBody = json_encode($postBody);
        }

        return $this->post($path, $postBody, $parameters, $headers);
    }
1296539
public function save(array $data, $key)
    {
        $file = $this->getFilename($key);

        $saved = $this->get($key)->merge($data);

        if (! is_dir(dirname($file))) {
            mkdir(dirname($file), 0777, true);
        }
        file_put_contents($file, json_encode($saved->all()));
    }
239431
protected function putData($file, $path, $data) {
		fseek($file, self::DATA_OFFSET);
		
		if (fwrite($file, serialize($data)) === false) {
			fclose($file);
			throw new OperationFailed('Unable to puth the cache content to: ' . $path);
		}
		
		ftruncate($file, ftell($file));
		fclose($file);
	}
729468
private function save($path, $annotations) {
        if (!is_dir(DATA . 'mapper'))
            mkdir(DATA . 'mapper', 0755, TRUE);

        $content = var_export($annotations, true);
        file_put_contents($path, '<' . '?php' . "\n\t" . 'return ' . str_replace("=> \n", ' => ', $content) . ";");

        $this->saveModelTable($this->getTableName(), get_called_class());
    }
250957
public static function createFromFile(string $path, bool $json = false): Schema
    {
        static::fileExists($path);

        $schema = $json ? json_decode(file_get_contents($path), true) : include $path;

        if (!is_array($schema)) {
            throw new InvalidArgumentException(
                '[createFromFile] method requires file that return a php array or json.'
            );
        }

        return new static($schema);
    }