MCPcopy Create free account
hub / github.com/francoispqt/gojay / ArrayKeyOmitEmpty

Method ArrayKeyOmitEmpty

encode_array.go:150–169  ·  view source on GitHub ↗

ArrayKeyOmitEmpty adds an array or slice to be encoded and skips if it is nil. Must be called inside an object as it will encode a key.

(key string, v MarshalerJSONArray)

Source from the content-addressed store, hash-verified

148// ArrayKeyOmitEmpty adds an array or slice to be encoded and skips if it is nil.
149// Must be called inside an object as it will encode a key.
150func (enc *Encoder) ArrayKeyOmitEmpty(key string, v MarshalerJSONArray) {
151 if enc.hasKeys {
152 if !enc.keyExists(key) {
153 return
154 }
155 }
156 if v.IsNil() {
157 return
158 }
159 enc.grow(5 + len(key))
160 r := enc.getPreviousRune()
161 if r != '{' {
162 enc.writeByte(',')
163 }
164 enc.writeByte('"')
165 enc.writeStringEscape(key)
166 enc.writeBytes(objKeyArr)
167 v.MarshalJSONArray(enc)
168 enc.writeByte(']')
169}
170
171// ArrayKeyNullEmpty adds an array or slice to be encoded and encodes `null`` if it is nil.
172// Must be called inside an object as it will encode a key.

Callers 2

AddArrayKeyOmitEmptyMethod · 0.95
MarshalJSONObjectMethod · 0.80

Calls 8

keyExistsMethod · 0.95
growMethod · 0.95
getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
writeStringEscapeMethod · 0.95
writeBytesMethod · 0.95
IsNilMethod · 0.65
MarshalJSONArrayMethod · 0.65

Tested by 1

MarshalJSONObjectMethod · 0.64