MCPcopy
hub / github.com/pocketbase/pocketbase / marshaledJSONtoFieldsList

Function marshaledJSONtoFieldsList

core/fields_list.go:181–206  ·  view source on GitHub ↗
(rawJSON []byte)

Source from the content-addressed store, hash-verified

179}
180
181func marshaledJSONtoFieldsList(rawJSON []byte) (FieldsList, error) {
182 extractedFields := FieldsList{}
183
184 // nothing to add
185 if len(rawJSON) == 0 {
186 return extractedFields, nil
187 }
188
189 // try to unmarshal first into a new fields list
190 // (assuming that rawJSON is array of objects)
191 err := json.Unmarshal(rawJSON, &extractedFields)
192 if err != nil {
193 // try again but wrap the rawJSON in []
194 // (assuming that rawJSON is a single object)
195 wrapped := make([]byte, 0, len(rawJSON)+2)
196 wrapped = append(wrapped, '[')
197 wrapped = append(wrapped, rawJSON...)
198 wrapped = append(wrapped, ']')
199 err = json.Unmarshal(wrapped, &extractedFields)
200 if err != nil {
201 return nil, fmt.Errorf("failed to unmarshal the provided JSON - expects array of objects or just single object: %w", err)
202 }
203 }
204
205 return extractedFields, nil
206}
207
208func (l *FieldsList) add(pos int, newField Field) {
209 fields := *l

Callers 2

AddMarshaledJSONMethod · 0.85
AddMarshaledJSONAtMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…