| 2402 | } |
| 2403 | |
| 2404 | func (j jsonArray) RemoveString(s string) (JSON, bool, error) { |
| 2405 | b := NewArrayBuilder(j.Len()) |
| 2406 | removed := false |
| 2407 | for _, el := range j { |
| 2408 | // We want to remove only elements of string type. |
| 2409 | if el.Type() == StringJSONType { |
| 2410 | t, err := el.AsText() |
| 2411 | if err != nil { |
| 2412 | return nil, false, err |
| 2413 | } |
| 2414 | if t == nil { |
| 2415 | return nil, false, errors.AssertionFailedf("StringJSONType should not be nil here") |
| 2416 | } |
| 2417 | if *t != s { |
| 2418 | b.Add(el) |
| 2419 | } else { |
| 2420 | removed = true |
| 2421 | } |
| 2422 | } else { |
| 2423 | b.Add(el) |
| 2424 | } |
| 2425 | } |
| 2426 | if removed { |
| 2427 | return b.Build(), removed, nil |
| 2428 | } |
| 2429 | return j, false, nil |
| 2430 | } |
| 2431 | |
| 2432 | func (j jsonObject) RemoveString(s string) (JSON, bool, error) { |
| 2433 | idx, ok := findPairIndexByKey(j, s) |