ParseJSON is a function that parses a JSON string that might contain multiple JSON objects and syntax errors in between by shifting the offset This for e.g. allow to parse { "foo": "bar" } invalid { "baz": "qux" } into [ { "foo": "bar" }, { "baz": "qux" } ] Credits to Michael Yang (https://github.co
(s string)
| 312 | // Now defaults to iterative parser for better streaming support |
| 313 | // Falls back to legacy parser if iterative parser fails |
| 314 | func ParseJSON(s string) ([]map[string]any, error) { |
| 315 | // Try iterative parser first (non-partial mode for complete parsing) |
| 316 | results, err := ParseJSONIterative(s, false) |
| 317 | if err == nil && len(results) > 0 { |
| 318 | return results, nil |
| 319 | } |
| 320 | // Fall back to legacy parser for backward compatibility |
| 321 | return parseJSONLegacy(s) |
| 322 | } |
| 323 | |
| 324 | // ParseJSONIterative parses JSON using the iterative parser |
| 325 | // Supports partial parsing for streaming scenarios |
no test coverage detected