API that converts unstructured data into structured JSON using OpenAI's GPT-4 model and validates the output using Zod schemas.
- Converts natural language text into structured JSON format
- Dynamic JSON schema validation using Zod
- Automatic retries on API failures
- Example-based prompting for consistent output
- TypeScript support
- Express - Web framework for Node.js
- OpenAI API - GPT-4 for text processing
- Zod - Runtime schema validation
- TypeScript - Type safety
Send a POST request to /api/json
with the following body structure:
{
"data": "Your unstructured text data here",
"format": {
// Your desired JSON schema format
}
}
{
"data": "Omkar is 20 years old and studies computer science at university",
"format": {
"name": { "type": "string" },
"age": { "type": "number" },
"isStudent": { "type": "boolean" },
"courses": {
"type": "array",
"items": { "type": "string" }
}
}
}
{
"name": "Omkar",
"age": 20,
"isStudent": true,
"courses": ["computer science"]
}
- Clone the repository
git clone https://github.com/omkaarvd/jsonapi.git
- Install dependencies:
bun install
- Create a
.env
file with your OpenAI API key:
AI_API_KEY=your_api_key_here
- Run the development server:
bun dev
The API validates both input and output using Zod schemas:
- Input validation ensures the request contains the required data and format fields
- Output validation ensures the AI-generated response matches the requested schema format