Skip to content

Commit 3eae366

Browse files
committed
feat: Adding docs
1 parent 156b3b9 commit 3eae366

11 files changed

Lines changed: 550 additions & 86 deletions

File tree

README.md

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Repair invalid JSON strings by automatically fixing common syntax errors like si
99
## Requirements
1010

1111
- PHP 8.3+
12+
- JSON PHP extension
1213

1314
## Installation
1415

@@ -41,93 +42,9 @@ $data = (new JsonRepairer($broken))->decode();
4142
$data = json_repair_decode($broken);
4243
```
4344

44-
## Configuration Options
45+
## Documentation
4546

46-
### Omit Empty Values
47-
48-
When repairing JSON from streaming sources (e.g., LLM responses), you may want to remove keys with missing values instead of adding empty strings:
49-
50-
```php
51-
// Missing value - defaults to adding empty string
52-
$broken = '{"name": "John", "age": }';
53-
$repaired = json_repair($broken);
54-
// {"name": "John", "age": ""}
55-
56-
// Remove keys with missing values
57-
$repaired = json_repair($broken, omitEmptyValues: true);
58-
// {"name": "John"}
59-
```
60-
61-
### Omit Incomplete Strings
62-
63-
Similarly, you can remove keys with incomplete string values instead of closing them:
64-
65-
```php
66-
// Incomplete string - defaults to closing the string
67-
$broken = '{"name": "John", "bio": "A developer who';
68-
$repaired = json_repair($broken);
69-
// {"name": "John", "bio": "A developer who"}
70-
71-
// Remove keys with incomplete strings
72-
$repaired = json_repair($broken, omitIncompleteStrings: true);
73-
// {"name": "John"}
74-
```
75-
76-
### Using Both Options Together
77-
78-
Both options can be used together, which is especially useful for streaming JSON where deltas are concatenated:
79-
80-
```php
81-
$broken = '{"name": "John", "age": , "bio": "A developer who';
82-
$repaired = json_repair($broken, omitEmptyValues: true, omitIncompleteStrings: true);
83-
// {"name": "John"}
84-
```
85-
86-
### Using with JsonRepairer Class
87-
88-
You can also pass these options to the `JsonRepairer` constructor:
89-
90-
```php
91-
$repairer = new JsonRepairer(
92-
$broken,
93-
ensureAscii: true,
94-
omitEmptyValues: true,
95-
omitIncompleteStrings: true
96-
);
97-
$repaired = $repairer->repair();
98-
```
99-
100-
Or with `json_repair_decode`:
101-
102-
```php
103-
$data = json_repair_decode(
104-
$broken,
105-
omitEmptyValues: true,
106-
omitIncompleteStrings: true
107-
);
108-
```
109-
110-
## Logging
111-
112-
The library supports PSR-3 logging for debugging repair operations. Pass any PSR-3 compatible logger to see what repairs are being made:
113-
114-
```php
115-
use Psr\Log\LoggerInterface;
116-
117-
// Using the helper function
118-
$repaired = json_repair($broken, logger: $logger);
119-
120-
// Using the class (implements LoggerAwareInterface)
121-
$repairer = new JsonRepairer($broken);
122-
$repairer->setLogger($logger);
123-
$repaired = $repairer->repair();
124-
```
125-
126-
Log messages include the position in the JSON string and a context snippet showing where the repair occurred. This is useful for:
127-
128-
- Debugging why certain repairs are being made
129-
- Understanding how malformed JSON is being interpreted
130-
- Tracking repair operations in production environments
47+
📚 **[View Full Documentation →](https://docs.cortexphp.com/json-repair)**
13148

13249
## Credits
13350

docs/assets/favicon.svg

Lines changed: 13 additions & 0 deletions
Loading

docs/assets/logo-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)