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

Method StripNulls

pkg/util/json/json.go:1569–1615  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1567 return j, false, nil
1568}
1569func (j jsonObject) StripNulls() (JSON, bool, error) {
1570 for i, e := range j {
1571 var json JSON
1572 var err error
1573 needToStrip := false
1574 hasNullValue := e.v.Type() == NullJSONType
1575 if !hasNullValue {
1576 json, needToStrip, err = e.v.StripNulls()
1577 if err != nil {
1578 return nil, false, err
1579 }
1580 }
1581 if hasNullValue || needToStrip {
1582 // Cannot return the original content, need to return the result
1583 // with new JSON object.
1584 numNotNulls := i
1585 for _, elem := range j[i:] {
1586 if elem.v.Type() != NullJSONType {
1587 numNotNulls++
1588 }
1589 }
1590 // Use number of fields not having null value to construct newObj
1591 // so that no need to grow the capacity of newObj.
1592 newObj := make(jsonObject, 0, numNotNulls)
1593 newObj = append(newObj, j[:i]...)
1594 if !hasNullValue {
1595 newObj = append(newObj, jsonKeyValuePair{
1596 k: e.k,
1597 v: json,
1598 })
1599 }
1600 for _, elem := range j[i+1:] {
1601 if elem.v.Type() != NullJSONType {
1602 if json, _, err = elem.v.StripNulls(); err != nil {
1603 return nil, false, err
1604 }
1605 newObj = append(newObj, jsonKeyValuePair{
1606 k: elem.k,
1607 v: json,
1608 })
1609 }
1610 }
1611 return newObj, true, nil
1612 }
1613 }
1614 return j, false, nil
1615}
1616
1617func (jsonNull) ObjectIter() (*ObjectIterator, error) {
1618 return nil, nil

Callers

nothing calls this directly

Calls 2

TypeMethod · 0.65
StripNullsMethod · 0.65

Tested by

no test coverage detected