Created
October 30, 2017 18:17
-
-
Save ReactiioN1337/8fe0cb9c821a582742bcdd720c70ffe3 to your computer and use it in GitHub Desktop.
PHP wrapper for json_encode/json_decode for an easier usage in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//---------------------------------------------------------------------- | |
// <author> ReactiioN </author> | |
// | |
// <file> json.php </file> | |
// | |
// <reference> | |
// https://secure.php.net/manual/en/function.json-encode.php | |
// https://secure.php.net/manual/de/function.json-decode.php | |
// </reference> | |
//---------------------------------------------------------------------- | |
abstract class json { | |
static public function parse($json_string, $as_array = false) { | |
return json_decode($json_string, $as_array); | |
} | |
static public function array_to_json($array, $as_string = false) { | |
$json_string = json::to_string($array); | |
return $as_string | |
? $json_string | |
: json::parse($json_string); | |
} | |
static public function to_array($json) { | |
return json::parse(json::to_string($json), true); | |
} | |
static public function to_string($json, $pretty = false) { | |
return $pretty | |
? json_encode($json, JSON_PRETTY_PRINT) | |
: json_encode($json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment