Skip to content

API that converts unstructured data into structured JSON using OpenAI's GPT-4 model and validates the output using Zod schemas.

Notifications You must be signed in to change notification settings

omkaarvd/jsonapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON API Converter

API that converts unstructured data into structured JSON using OpenAI's GPT-4 model and validates the output using Zod schemas.

Features

  • 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

Tech Stack

API Usage

Send a POST request to /api/json with the following body structure:

{
  "data": "Your unstructured text data here",
  "format": {
    // Your desired JSON schema format
  }
}

Example Request

{
  "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" }
    }
  }
}

Example Response

{
  "name": "Omkar",
  "age": 20,
  "isStudent": true,
  "courses": ["computer science"]
}

Installation

  1. Clone the repository
git clone https://github.com/omkaarvd/jsonapi.git
  1. Install dependencies:
bun install
  1. Create a .env file with your OpenAI API key:
AI_API_KEY=your_api_key_here
  1. Run the development server:
bun dev

Schema Validation

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

About

API that converts unstructured data into structured JSON using OpenAI's GPT-4 model and validates the output using Zod schemas.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published