Skip to content

Instantly share code, notes, and snippets.

@graceman9
Created November 9, 2022 19:58
Show Gist options
  • Save graceman9/7829c84efdf79efe8640f421f70fa077 to your computer and use it in GitHub Desktop.
Save graceman9/7829c84efdf79efe8640f421f70fa077 to your computer and use it in GitHub Desktop.
Adminer plugin Jason pretty print based on json-column.php official plugin
<?php
/** Display JSON values as table in edit
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @author Martin Zeman (Zemistr), http://www.zemistr.eu/
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerJsonColumn {
private function _testJson($value) {
if ((substr($value, 0, 1) == '{' || substr($value, 0, 1) == '[') && ($json = json_decode($value, true))) {
return $json;
}
return $value;
}
function editInput($table, $field, $attrs, $value) {
$json = $this->_testJson($value);
if ($json !== $value) {
echo '<pre>' . json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '</pre>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment