{
  "openapi": "3.0.3",
  "info": {
    "title": "ConvertJSON API",
    "description": "Convert between JSON and CSV formats. Supports customizable delimiters, headers, and quoting options.",
    "version": "1.0.0",
    "contact": {
      "name": "aiyaiyai",
      "url": "https://aiyaiyai.click",
      "email": "hello@aiyaiyai.click"
    }
  },
  "servers": [
    {
      "url": "https://convertjson-ashen.vercel.app",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/json-to-csv": {
      "post": {
        "operationId": "jsonToCsv",
        "summary": "Convert JSON array to CSV",
        "description": "Converts an array of objects to CSV format. Automatically detects all unique keys as columns.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["data"],
                "properties": {
                  "data": {
                    "type": "array",
                    "description": "Array of objects to convert",
                    "items": {
                      "type": "object"
                    },
                    "minItems": 1
                  },
                  "options": {
                    "type": "object",
                    "properties": {
                      "delimiter": {
                        "type": "string",
                        "default": ",",
                        "description": "Column separator character"
                      },
                      "headers": {
                        "type": "boolean",
                        "default": true,
                        "description": "Include header row"
                      },
                      "quote": {
                        "type": "string",
                        "default": "\"",
                        "description": "Quote character for escaping"
                      },
                      "download": {
                        "type": "boolean",
                        "default": false,
                        "description": "Return as file download instead of JSON"
                      },
                      "filename": {
                        "type": "string",
                        "default": "data",
                        "description": "Filename for download (without extension)"
                      }
                    }
                  }
                }
              },
              "example": {
                "data": [
                  {"name": "Alice", "age": 30, "city": "Berlin"},
                  {"name": "Bob", "age": 25, "city": "Munich"}
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Converted CSV data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "csv": {
                      "type": "string",
                      "description": "The CSV formatted data"
                    },
                    "rows": {
                      "type": "integer",
                      "description": "Number of data rows"
                    },
                    "columns": {
                      "type": "integer",
                      "description": "Number of columns"
                    }
                  }
                },
                "example": {
                  "csv": "name,age,city\nAlice,30,Berlin\nBob,25,Munich",
                  "rows": 2,
                  "columns": 3
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                },
                "description": "When options.download is true"
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/csv-to-json": {
      "post": {
        "operationId": "csvToJson",
        "summary": "Convert CSV to JSON array",
        "description": "Parses CSV data into an array of objects. Handles quoted fields and custom delimiters.",
        "parameters": [
          {
            "name": "delimiter",
            "in": "query",
            "schema": {
              "type": "string",
              "default": ","
            },
            "description": "Column separator character"
          },
          {
            "name": "headers",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["true", "false"],
              "default": "true"
            },
            "description": "Whether first row contains headers"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["csv"],
                "properties": {
                  "csv": {
                    "type": "string",
                    "description": "CSV formatted data"
                  }
                }
              },
              "example": {
                "csv": "name,age,city\nAlice,30,Berlin\nBob,25,Munich"
              }
            },
            "text/csv": {
              "schema": {
                "type": "string"
              },
              "example": "name,age,city\nAlice,30,Berlin\nBob,25,Munich"
            },
            "text/plain": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Converted JSON data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      },
                      "description": "Array of parsed objects"
                    },
                    "rows": {
                      "type": "integer",
                      "description": "Number of data rows"
                    },
                    "columns": {
                      "type": "integer",
                      "description": "Number of columns"
                    },
                    "headers": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Column headers"
                    }
                  }
                },
                "example": {
                  "data": [
                    {"name": "Alice", "age": "30", "city": "Berlin"},
                    {"name": "Bob", "age": "25", "city": "Munich"}
                  ],
                  "rows": 2,
                  "columns": 3,
                  "headers": ["name", "age", "city"]
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message"
          },
          "details": {
            "type": "string",
            "description": "Additional error details"
          }
        }
      }
    }
  },
  "x-ai-hints": {
    "usage": "Use this API to convert data between JSON and CSV formats. Useful for data transformation, export/import operations, and spreadsheet integration.",
    "tips": [
      "JSON to CSV: Input must be an array of objects with consistent keys",
      "CSV to JSON: First row is treated as headers by default",
      "Quoted fields (containing commas or newlines) are handled automatically"
    ]
  }
}
