random-web-tools/api/php/php_array_to_json.php
2023-12-12 14:10:29 +02:00

22 lines
424 B
PHP

<?php
require_once 'cors.php';
$input = json_decode(file_get_contents('php://input'), true);
$data = $input['data'];
$minify_json = $input['minify_json'];
try {
eval("\$data_array = {$data};");
$json = @json_encode($data_array, JSON_UNESCAPED_UNICODE | ($minify_json ? null : JSON_PRETTY_PRINT));
echo json_encode([
'data' => $json,
]);
} catch (Throwable $exception) {
echo json_encode([
'data' => '',
]);
}