MCPcopy
hub / github.com/pocketbase/pocketbase / MarshalJSON

Method MarshalJSON

core/fields_list.go:335–359  ·  view source on GitHub ↗

MarshalJSON implements the [json.Marshaler] interface.

()

Source from the content-addressed store, hash-verified

333
334// MarshalJSON implements the [json.Marshaler] interface.
335func (l FieldsList) MarshalJSON() ([]byte, error) {
336 if l == nil {
337 l = []Field{} // always init to ensure that it is serialized as empty array
338 }
339
340 wrapper := make([]map[string]any, 0, len(l))
341
342 for _, f := range l {
343 // precompute the json into a map so that we can append the type to a flatten object
344 raw, err := json.Marshal(f)
345 if err != nil {
346 return nil, err
347 }
348
349 data := map[string]any{}
350 if err := json.Unmarshal(raw, &data); err != nil {
351 return nil, err
352 }
353 data["type"] = f.Type()
354
355 wrapper = append(wrapper, data)
356 }
357
358 return json.Marshal(wrapper)
359}
360
361// Value implements the [driver.Valuer] interface.
362func (l FieldsList) Value() (driver.Value, error) {

Callers 1

TestFieldsListJSONFunction · 0.95

Calls 1

TypeMethod · 0.65

Tested by 1

TestFieldsListJSONFunction · 0.76