Metadata-Version: 2.4
Name: jsonish_py
Version: 0.0.1
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pytest>=8.4.1 ; extra == 'dev'
Provides-Extra: dev
Summary: Wrapper around `jsonish` from BAML
Author-email: Noam Finkelstein <noam.finkelstein@liquid.ai>
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# jsonish_py

A Python wrapper around [BAML's jsonish crate](https://github.com/BoundaryML/baml/tree/canary/engine/baml-lib/jsonish) for flexible JSON-like parsing.

## Overview

This library uses BAML's Rust-based `jsonish` parser to handle malformed or non-standard JSON strings that regular parsers would reject. It provides two main functions:

- **`parse_to_json`** - Parses JSON-like strings into standard JSON
- **`parse_to_model`** - A utility that combines parsing with Pydantic model validation

## Installation

```bash
pip install jsonish_py
```

## Usage

### Basic JSON parsing

```python
import jsonish_py

# Standard JSON works fine
result = jsonish_py.parse_to_json('{"name": "John", "age": 30}')
# Returns: '{"name": "John", "age": 30}'

# But it also handles malformed JSON
result = jsonish_py.parse_to_json('{"name": John, "age": 30,}')  # Missing quotes, trailing comma
result = jsonish_py.parse_to_json("{'name': 'John'}")  # Single quotes
```

### Parsing to Pydantic models

```python
from pydantic import BaseModel
import jsonish_py

class User(BaseModel):
    name: str
    age: int

# Parse directly to a Pydantic model
user = jsonish_py.parse_to_model('{"name": "Alice", "age": 25}', User)
print(user.name)  # Alice
print(user.age)   # 25
```

