diff --git a/internal/encoder/encoder.go b/internal/encoder/encoder.go index ad9ced5..3c6db04 100644 --- a/internal/encoder/encoder.go +++ b/internal/encoder/encoder.go @@ -468,7 +468,7 @@ func AppendMarshalJSONIndent(ctx *RuntimeContext, code *Opcode, b []byte, v inte if err := Indent( &indentBuf, compactBuf.Bytes(), - string(ctx.Prefix)+strings.Repeat(string(ctx.IndentStr), ctx.BaseIndent+indent+1), + string(ctx.Prefix)+strings.Repeat(string(ctx.IndentStr), ctx.BaseIndent+indent), string(ctx.IndentStr), ); err != nil { return nil, &errors.MarshalerError{Type: reflect.TypeOf(v), Err: err} diff --git a/internal/encoder/vm_escaped_indent/vm.go b/internal/encoder/vm_escaped_indent/vm.go index 88799c8..02af6d3 100644 --- a/internal/encoder/vm_escaped_indent/vm.go +++ b/internal/encoder/vm_escaped_indent/vm.go @@ -2853,7 +2853,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -2899,7 +2899,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -2946,7 +2946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent+1) b = append(b, code.EscapedKey...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, true) if err != nil { return nil, err } @@ -2988,7 +2988,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -3030,7 +3030,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent+1) b = append(b, code.EscapedKey...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -3877,7 +3877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -3898,7 +3898,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent) b = append(b, code.EscapedKey...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -3913,7 +3913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } @@ -3928,7 +3928,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent) b = append(b, code.EscapedKey...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, true) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, true) if err != nil { return nil, err } diff --git a/internal/encoder/vm_indent/vm.go b/internal/encoder/vm_indent/vm.go index c2229d3..c3e54cc 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -2859,7 +2859,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -2905,7 +2905,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -2952,7 +2952,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent+1) b = append(b, code.Key...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, iface, code.Indent+1, false) if err != nil { return nil, err } @@ -2994,7 +2994,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -3036,7 +3036,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent+1) b = append(b, code.Key...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -3883,7 +3883,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 && code.Nilcheck { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -3904,7 +3904,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent) b = append(b, code.Key...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -3919,7 +3919,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt if p == 0 { b = appendNull(b) } else { - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err } @@ -3934,7 +3934,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt b = appendIndent(ctx, b, code.Indent) b = append(b, code.Key...) b = append(b, ' ') - bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent, false) + bb, err := appendMarshalJSON(ctx, code, b, ptrToInterface(code, p), code.Indent+1, false) if err != nil { return nil, err }