gabriel/yajl-objc logo

gabriel/yajl-objc

Free

Objective-C bindings for YAJL (Yet Another JSON Library) C library

FreeFree tier
Type
Open Source

About gabriel/yajl-objc

yajl-objc provides Objective-C bindings for YAJL (Yet Another JSON Library), a C library for SAX-style JSON parsing. It offers stream parsing capabilities, support for comments in JSON, improved error messages, and proper handling of large numeric types. Developers can parse JSON from NSString or NSData, generate JSON from Objective-C objects (NSArray, NSDictionary, etc.), and use a document-style parser. The library supports integration via CocoaPods ('YAJLO' pod) and Swift Package Manager. It includes options for allowing comments, checking UTF-8, and enforcing strict numeric precision. The streaming parser (YAJLParser) enables delegate-based parsing for large or incremental data.

Key Features

Stream parsing (SAX-style) for large or incremental JSON data
Support for comments in JSON during parsing
Better error messages compared to standard JSON parsers
Parse directly from NSString or NSData
Generate JSON from Objective-C objects (NSArray, NSDictionary, custom types)
Proper handling of large numeric types
Document-style parser for in-memory JSON representation
Error handling via exception or out error parameter
Options: allow comments, check UTF-8, force strict precision
Integration via CocoaPods or Swift Package Manager

Pros & Cons

Pros
  • Stream parsing reduces memory usage for large JSON documents
  • User-friendly error messages help debug malformed JSON
  • Supports JSON comments, useful for configuration files
  • Properly handles large integers without precision loss
  • Multiple integration options (CocoaPods, SPM) for convenience
  • Well-documented usage examples in README
  • Flexible parser options to validate UTF-8 or enforce strict numeric precision
Cons
  • Limited to Objective-C; requires bridging for Swift, though Xcode supports mixed-language projects
  • No built-in support for modern JSON features like KeyPaths or Codable (available in Swift)
  • Project maintenance status is unclear; last commit may be several years old
  • Not an AI-specific tool; it's a general-purpose JSON library

Best For

Parsing JSON data from file or network in Objective-C applicationsGenerating JSON strings from native Objective-C objectsStreaming parsing of large JSON payloads to avoid memory overheadDeserializing JSON with comments (non-standard) for configuration files

FAQ

How do I parse JSON from an NSString?
Use the category method on NSString: call `[jsonString yajl_JSON]` or `[jsonString yajl_JSONWithOptions:error:]` to get an NSArray or NSDictionary.
Can I generate beautified JSON with custom indentation?
Yes, use `yajl_JSONStringWithOptions:indentString:` on an NSObject (like NSDictionary) with YAJLGenOptionsBeautify and your custom indent string.
Does yajl-objc support streaming JSON parsing?
Yes, the YAJLParser class provides a SAX-style streaming parser. Set a delegate conforming to YAJLParserDelegate to receive callbacks as the JSON is parsed incrementally.
How can I integrate yajl-objc into my project?
You can use CocoaPods with the pod 'YAJLO', or use Swift Package Manager by adding the repository URL (https://github.com/gabriel/yajl-objc.git) with version >= 0.3.4.