MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / jsonNode

Method jsonNode

pkg/sql/sem/tree/pretty.go:2502–2531  ·  view source on GitHub ↗

jsonNode pretty prints a JSON node.

(j json.JSON)

Source from the content-addressed store, hash-verified

2500
2501// jsonNode pretty prints a JSON node.
2502func (p *PrettyCfg) jsonNode(j json.JSON) pretty.Doc {
2503 // Figure out what type this is.
2504 if it, _ := j.ObjectIter(); it != nil {
2505 // Object.
2506 elems := make([]pretty.Doc, 0, j.Len())
2507 for it.Next() {
2508 elems = append(elems, p.nestUnder(
2509 pretty.Concat(
2510 pretty.Text(json.FromString(it.Key()).String()),
2511 pretty.Text(`:`),
2512 ),
2513 p.jsonNode(it.Value()),
2514 ))
2515 }
2516 return p.bracket("{", p.commaSeparated(elems...), "}")
2517 } else if n := j.Len(); n > 0 {
2518 // Non-empty array.
2519 elems := make([]pretty.Doc, n)
2520 for i := 0; i < n; i++ {
2521 elem, err := j.FetchValIdx(i)
2522 if err != nil {
2523 return pretty.Text(j.String())
2524 }
2525 elems[i] = p.jsonNode(elem)
2526 }
2527 return p.bracket("[", p.commaSeparated(elems...), "]")
2528 }
2529 // Other.
2530 return pretty.Text(j.String())
2531}

Callers 1

jsonStringMethod · 0.95

Calls 13

nestUnderMethod · 0.95
bracketMethod · 0.95
commaSeparatedMethod · 0.95
ConcatFunction · 0.92
TextFunction · 0.92
FromStringFunction · 0.92
KeyMethod · 0.80
ObjectIterMethod · 0.65
LenMethod · 0.65
NextMethod · 0.65
StringMethod · 0.65
FetchValIdxMethod · 0.65

Tested by

no test coverage detected