🤖 AI Summary
A new Swift library, PartialJSON, was released to parse incomplete or streaming JSON—useful for truncated API responses, streaming LLM outputs, and progressive UI updates. Inspired by OpenAI’s Node.js approach and the Promplate partial-JSON parser, the project ports and adapts those parsing strategies to Swift with Swift-specific optimizations. It’s zero-dependency, has full test coverage, targets Swift 5.5+/Swift 6 compatibility and modern Apple platforms, and installs via Swift Package Manager or Xcode’s package UI.
Technically, PartialJSON first tries native JSONSerialization for complete payloads and falls back to a partial parser that uses efficient String.Index operations to minimize memory overhead and be streaming-friendly. It supports all JSON types (objects, arrays, strings, numbers, booleans, null) plus special numeric values (Infinity, -Infinity, NaN). Parsing behavior is configurable with fine-grained options (.array, .object, .string, .number, .null, .boolean, .nan, .infinity, convenience masks like .collections/.allExceptNumbers/.all). The API exposes clear error types for incomplete vs. malformed JSON (with position info), a simple StreamingParser example for incremental appends, and usage patterns for showing partial results while loading or recovering from truncated LLM responses—making it practical for AI/ML engineers integrating streaming model outputs into apps.
Loading comments...
login to comment
loading comments...
no comments yet