PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/onbloc/json/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
onbloc / json
Files
24 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/onbloc/json/v0
gno
0.9

Files (24)

  • README.mdmarkdown
  • gnomod.tomltoml
  • buffer.gnogno
  • builder.gnogno
  • decode.gnogno
  • encode.gnogno
  • errors.gnogno
  • escape.gnogno
  • indent.gnogno
  • internal.gnogno
  • node.gnogno
  • parser.gnogno
  • path.gnogno
  • token.gnogno
  • buffer_test.gnogno
  • builder_test.gnogno
  • decode_test.gnogno
  • encode_test.gnogno
  • escape_test.gnogno
  • indent_test.gnogno
  • node_test.gnogno
  • parser_test.gnogno
  • path_test.gnogno
  • LICENSEother
  • indent_test.gnogno
    1package json23import (4	"bytes"5	"testing"6)78func TestIndentJSON(t *testing.T) {9	tests := []struct {10		name     string11		input    []byte12		indent   string13		expected []byte14	}{15		{16			name:     "empty object",17			input:    []byte(`{}`),18			indent:   "  ",19			expected: []byte(`{}`),20		},21		{22			name:     "empty array",23			input:    []byte(`[]`),24			indent:   "  ",25			expected: []byte(`[]`),26		},27		{28			name:     "nested object",29			input:    []byte(`{{}}`),30			indent:   "\t",31			expected: []byte("{\n\t\t{}\n}"),32		},33		{34			name:     "nested array",35			input:    []byte(`[[[]]]`),36			indent:   "\t",37			expected: []byte("[[\n\t\t[\n\t\t\t\t\n\t\t]\n]]"),38		},39		{40			name:     "top-level array",41			input:    []byte(`["apple","banana","cherry"]`),42			indent:   "\t",43			expected: []byte(`["apple","banana","cherry"]`),44		},45		{46			name:     "array of arrays",47			input:    []byte(`["apple",["banana","cherry"],"date"]`),48			indent:   "  ",49			expected: []byte("[\"apple\",[\n    \"banana\",\n    \"cherry\"\n],\"date\"]"),50		},5152		{53			name:     "nested array in object",54			input:    []byte(`{"fruits":["apple",["banana","cherry"],"date"]}`),55			indent:   "  ",56			expected: []byte("{\n    \"fruits\": [\"apple\",[\n        \"banana\",\n        \"cherry\"\n    ],\"date\"]\n}"),57		},58		{59			name:     "complex nested structure",60			input:    []byte(`{"data":{"array":[1,2,3],"bool":true,"nestedArray":[["a","b"],"c"]}}`),61			indent:   "  ",62			expected: []byte("{\n    \"data\": {\n        \"array\": [1,2,3],\"bool\": true,\"nestedArray\": [[\n            \"a\",\n            \"b\"\n        ],\"c\"]\n    }\n}"),63		},64		{65			name:     "custom ident character",66			input:    []byte(`{"fruits":["apple",["banana","cherry"],"date"]}`),67			indent:   "*",68			expected: []byte("{\n**\"fruits\": [\"apple\",[\n****\"banana\",\n****\"cherry\"\n**],\"date\"]\n}"),69		},70	}7172	for _, tt := range tests {73		t.Run(tt.name, func(t *testing.T) {74			actual, err := Indent(tt.input, tt.indent)75			if err != nil {76				t.Errorf("IndentJSON() error = %v", err)77				return78			}79			if !bytes.Equal(actual, tt.expected) {80				t.Errorf("IndentJSON() = %q, want %q", actual, tt.expected)81			}82		})83	}84}85

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.