Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/jsonview/staticdisplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ func formatJSONObject(result gjson.Result, indent, width int) string {
if len(keys) == 0 {
return nullValueStyle.Render("(empty)")
}
values := result.Map()

var items []string
for _, key := range keys {
value := result.Get(key.Str)
value := values[key.Str]
keyStr := getIndent(indent) + keyStyle.Render(sanitizeTerminalString(key.Str)+":")
// If item will be a one-liner, put it inline after the key, otherwise
// it starts with a newline and goes below the key.
Expand Down
18 changes: 18 additions & 0 deletions internal/jsonview/staticdisplay_literal_keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package jsonview

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)

func TestStaticDisplayUsesLiteralObjectKeys(t *testing.T) {
t.Parallel()

result := gjson.Parse(`{"a.b":"literal-value","a":{"b":"nested-value"}}`)
out := formatJSON(result, 80)

require.Contains(t, out, "literal-value")
require.Contains(t, out, "nested-value")
}