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

Method jsonNode

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

jsonNode pretty prints a JSON node.

(j json.JSON)

Source from the content-addressed store, hash-verified

2172
2173// jsonNode pretty prints a JSON node.
2174func (p *PrettyCfg) jsonNode(j json.JSON) pretty.Doc {
2175 // Figure out what type this is.
2176 if it, _ := j.ObjectIter(); it != nil {
2177 // Object.
2178 elems := make([]pretty.Doc, 0, j.Len())
2179 for it.Next() {
2180 elems = append(elems, p.nestUnder(
2181 pretty.Concat(
2182 pretty.Text(json.FromString(it.Key()).String()),
2183 pretty.Text(`:`),
2184 ),
2185 p.jsonNode(it.Value()),
2186 ))
2187 }
2188 return p.bracket("{", p.commaSeparated(elems...), "}")
2189 } else if n := j.Len(); n > 0 {
2190 // Non-empty array.
2191 elems := make([]pretty.Doc, n)
2192 for i := 0; i < n; i++ {
2193 elem, err := j.FetchValIdx(i)
2194 if err != nil {
2195 return pretty.Text(j.String())
2196 }
2197 elems[i] = p.jsonNode(elem)
2198 }
2199 return p.bracket("[", p.commaSeparated(elems...), "]")
2200 }
2201 // Other.
2202 return pretty.Text(j.String())
2203}

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