MCPcopy Index your code
hub / github.com/mudler/LocalAI / ParseJSON

Function ParseJSON

pkg/functions/parse.go:314–322  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

312// Now defaults to iterative parser for better streaming support
313// Falls back to legacy parser if iterative parser fails
314func 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

Callers 2

parse_test.goFile · 0.85
ParseFunctionCallFunction · 0.85

Calls 2

ParseJSONIterativeFunction · 0.85
parseJSONLegacyFunction · 0.85

Tested by

no test coverage detected