AsMap returns a representation of the Node as a map[string]any
()
| 254 | |
| 255 | // AsMap returns a representation of the Node as a map[string]any |
| 256 | func (n *Node) AsMap() map[string]any { |
| 257 | if n.Type() != "object" { |
| 258 | return map[string]any{} |
| 259 | } |
| 260 | |
| 261 | pairs := n.NamedChildren() |
| 262 | |
| 263 | out := make(map[string]any, len(pairs)) |
| 264 | |
| 265 | for _, pair := range pairs { |
| 266 | if pair.Type() != "pair" { |
| 267 | continue |
| 268 | } |
| 269 | |
| 270 | key := DecodeString(pair.ChildByFieldName("key").RawString()) |
| 271 | value := pair.ChildByFieldName("value").AsGoType() |
| 272 | |
| 273 | out[key] = value |
| 274 | } |
| 275 | return out |
| 276 | } |
| 277 | |
| 278 | // AsArray returns a representation of the Node as a []any |
| 279 | func (n *Node) AsArray() []any { |
no test coverage detected