JSON
class JSON (View source)
The GenericDatabase\Helpers\Parsers\JSON class provides two static methods for working with JSON data.
The isValidJSON method checks if a given string is a valid JSON, and the parseJSON method parses a valid JSON string into an array.
Example Usage:
// Parse an INI file and retrieve its contents as an array
$json = '{"name": "John", "age": 30}';
$isValid = JSON::isValidJSON($json);
Output: $isValid is being true
// Parse a valid JSON string into an array
$json = '{"name": "John", "age": 30}';
$data = JSON::parseJSON($json);
Output: $data will be an array containing the parsed JSON data
Main functionalities:
- Check if a string is a valid JSON
- Parse a valid JSON string into an array
Methods:
isValidJSON($json): Checks if a given string is a valid JSON. Returns a boolean value indicating the result.parseJSON($json): Parses a valid JSON string into an array. Returns the parsed JSON data as an array.
Methods
static bool
isValidJSON(mixed $json)
Detect if json is valid
static array
parseJSON(string $json)
Parse a valid json
Details
static bool
isValidJSON(mixed $json)
Detect if json is valid
static array
parseJSON(string $json)
Parse a valid json