summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
Diffstat (limited to 'it.class')
-rw-r--r--it.class16
1 files changed, 16 insertions, 0 deletions
diff --git a/it.class b/it.class
index f514537..e0916c3 100644
--- a/it.class
+++ b/it.class
@@ -1006,5 +1006,21 @@ static function pipe($cmd, $args = array())
return new it_pipe(is_string($cmd) ? array('cmd' => $cmd, 'args' => $args) : array('data' => $cmd));
}
+/**
+ * Encodes data to json with unescaped slahes, unescape unicode and on devel pretty printing
+ */
+static function json_encode($data)
+{
+ return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | (it::is_devel() ? JSON_PRETTY_PRINT : 0));
+}
+
+/**
+ * Decodes json data and provides warning if failed
+ */
+static function json_decode($json)
+{
+ return ($data = json_decode($json)) === null && $json != 'null' ? it::error(array('title' => "invalid json", 'body' => $json)) : $data;
+}
+
}
?>