From a23b541455feed9db39b71b54188422ee82c01ca Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Mon, 7 Jul 2014 18:22:08 +0200
Subject: [PATCH] Allow the user to specify the starting indentation level to
 JSON.encode

---
 src/post_modules/JSON/json.cmod | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/post_modules/JSON/json.cmod b/src/post_modules/JSON/json.cmod
index 5aed841270..c67cfe1ff7 100644
--- a/src/post_modules/JSON/json.cmod
+++ b/src/post_modules/JSON/json.cmod
@@ -451,13 +451,14 @@ static void json_encode_recur (struct encode_context *ctx, struct svalue *val)
  *! @[escape_string]
  */
 PIKEFUN string encode (int|float|string|array|mapping|object val,
-		       void|int flags, void|function|object|program|string callback)
+                       void|int flags, void|function|object|program|string callback,
+                       void|int base_indent )
   optflags OPT_TRY_OPTIMIZE;
 {
   struct encode_context ctx;
   ONERROR uwp;
   ctx.flags = (flags ? flags->u.integer : 0);
-  ctx.indent = (ctx.flags & HUMAN_READABLE ? 0 : -1);
+  ctx.indent = (ctx.flags & HUMAN_READABLE ? base_indent ? base_indent->u.integer : 0 : -1);
   ctx.callback = callback;
   init_string_builder (&ctx.buf, 0);
   SET_ONERROR (uwp, free_string_builder, &ctx.buf);
-- 
GitLab