Skip to content

Commit 22b4ae6

Browse files
committed
Merge to Rust
1 parent 6cba357 commit 22b4ae6

22 files changed

+666
-924
lines changed

.gitignore

-42
This file was deleted.

LICENSE

-21
This file was deleted.

README.md

+44-32
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
11
# JSONFixer4J 🛠️
22

3-
A lightweight Java library for automatically correcting broken JSON strings. Whether you have mismatched brackets, missing commas, or incomplete literals, **JSONFixer4J** tries its best to fix them so you can keep on coding without interruptions! ⚙️
3+
A fast and efficient tool for automatically correcting broken JSON strings, written in Rust for maximum performance and with JNI for Java integration. Whether you have mismatched brackets, missing commas, or incomplete literals, **JSONFixer4J** fixes them efficiently! ⚙️
44

55
## Features
66
- 🧩 **Bracket Correction**: Fixes unmatched `{` or `}`.
77
- 🎯 **Comma Insertion**: Inserts missing commas between keys/values.
88
- 🔤 **String Completion**: Completes unterminated strings.
99
-**Literal Recovery**: Fixes partial boolean (`true`, `false`) or null (`null`) literals.
10+
- 🚀 **Fast**: Written inRust for exceptional performance.
1011

11-
## Quick Start
12+
## Installation
1213

13-
### Installation
14-
15-
Add **JSONFixer4J** to your Gradle project:
14+
Clone the repository:
15+
```bash
16+
git clone https://github.com/DedInc/jsonfixer4j
17+
```
1618

17-
```groovy
18-
repositories {
19-
mavenCentral()
20-
maven { url "https://jitpack.io" }
21-
}
19+
Navigate to the Rust implementation directory:
20+
```bash
21+
cd jsonfixer4j/jsonfixer_rust
22+
```
2223

23-
dependencies {
24-
// ...
25-
implementation 'com.github.DedInc:jsonfixer4j:b7a6d1109c'
26-
}
24+
Build the project:
25+
```bash
26+
cargo build --release
2727
```
2828

29-
> **Note**: Above is an example of a **build.gradle** file. If JSONFixer4J is not yet available via JitPack, you might need to install it locally or reference it as a local library.
29+
The built binary will be available in the `target/release` directory with .dll or .so extension.
3030

31-
### Usage
31+
### Pre-built Binaries
3232

33-
In your Java code, simply create an instance of `JSONAutoCorrector` and call `autocorrect(...)` with your broken JSON string.
33+
Pre-built binaries are available in the [latest release](https://github.com/DedInc/jsonfixer4j/releases/latest) built on:
34+
- Linux (Ubuntu 22.04.5 LTS x86_64) [.so]
35+
- Windows 10 (x64) [.dll]
3436

35-
```java
36-
package org.example;
37+
## Integration with Java via JNI
3738

38-
import com.github.dedinc.jsonfixer4j.JSONAutoCorrector;
39+
JSONFixer4J can be integrated with Java applications using JNI (Java Native Interface) via native. This allows you to leverage the performance benefits of Rust while working within your Java codebase.
40+
41+
### Usage Example
42+
43+
```java
44+
import com.github.dedinc.jsonfixer4j.JSONFixerRust;
3945

4046
public class Main {
4147
public static void main(String[] args) {
42-
final JSONAutoCorrector corrector = new JSONAutoCorrector();
48+
JSONFixerRust corrector = new JSONFixerRust();
4349

4450
String[] brokenCases = {
45-
"{\"key\": 123", // Missing closing brace
46-
"{{\"name\": \"Test\"}", // Extra brace at the start
47-
"{\"arr\": [1, 2, 3}", // Missing closing bracket for array
48-
"{\"key\": \"test\", \"star, ", // Unfinished key
49-
"{\"key\": \"test\", \"new\": fals",// Incomplete boolean
50-
"{\"title\": \"Hello", // Unterminated string
51-
"{\"key1\": 1, \"key2\": 2,", // Trailing comma
52-
"{\"one\": 1 \"two\": 2}", // Missing comma
53-
"{\"flag\": tr, \"value\": nul}" // Partial literals
51+
"{\"key\": 123", // Missing closing brace
52+
"{{\"name\": \"Test\"}", // Extra brace at the start
53+
"{\"arr\": [1, 2, 3}", // Missing closing bracket for array
54+
"{\"key\": \"test\", \"star, ", // Unfinished key
55+
"{\"key\": \"test\", \"new\": fals",// Incomplete boolean
56+
"{\"title\": \"Hello", // Unterminated string
57+
"{\"key1\": 1, \"key2\": 2,", // Trailing comma
58+
"{\"one\": 1 \"two\": 2}", // Missing comma
59+
"{\"flag\": tr, \"value\": nul}" // Partial literals
5460
};
5561

5662
for (String broken : brokenCases) {
@@ -63,8 +69,14 @@ public class Main {
6369
}
6470
```
6571

66-
This will attempt to fix each broken JSON string and print both the original and fixed versions in the console.
72+
## Why Rust?
73+
74+
The Rust implementation provides several advantages:
75+
76+
1. **Performance**: Significantly faster JSON processing compared to the Java version.
77+
2. **Memory Safety**: Rust's ownership system prevents common programming errors.
78+
3. **No Garbage Collection**: Predictable performance without GC pauses.
6779

6880
---
6981

70-
Made with ❤️ and Java.
82+
Made with ❤️, Rust, and Java.

build.gradle

-10
This file was deleted.

gradle/wrapper/gradle-wrapper.jar

-59.3 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

-6
This file was deleted.

0 commit comments

Comments
 (0)