Trexmi
Converter Ready

JSON to OpenAI Function Schema

Convert representative JSON arguments into an OpenAI function tool definition for the Responses API or Chat Completions.

Generate Responses API function format Generate Chat Completions function wrapper Infer nested JSON parameter types Create required arrays and additionalProperties false
A sample shows observed values, not every valid value. Edit the generated JSON Schema before using it in an API request.
INPUT Sample JSON *
0 chars0 words0 lines

Tool settings

Ctrl / ⌘ + Enter
OpenAI function tool schema Review descriptions, required fields, nullability, and arrays before production use.
About the tool

What JSON to OpenAI Function Schema does

JSON to OpenAI Function Schema converts a sample JSON value into a function tool definition. Choose the flattened tool format used by the Responses API or the nested function wrapper used by Chat Completions. The generated parameters object is a JSON Schema inferred from the sample.

Generation is deterministic and does not call an OpenAI model. Object properties are inferred recursively, observed fields are marked required, and generated objects use additionalProperties: false. These defaults provide a strict starting point, but a single example cannot identify optional arguments, field descriptions, enum choices, ranges, formats, or every valid array item.

JSON to OpenAI Function Schema with Responses and Chat Completions formats
Generate the provider wrapper and parameter schema, then review the inferred contract.

How to use

  1. Add sample arguments. Paste valid JSON containing realistic names and value types.
  2. Name the function. Use a stable programmatic identifier such as get_weather.
  3. Write the description. Explain what the function does and when the model should call it.
  4. Select API format. Choose Responses API or Chat Completions and decide whether strict mode is enabled.
  5. Edit the schema. Add property descriptions, enums, ranges, formats, and correct optional or nullable fields before integration.
Built for the task

Why use JSON to OpenAI Function Schema?

Focused controls, predictable output, and a workflow designed around this exact transformation.

01

Two OpenAI formats

Generate either a flattened Responses function tool or the nested Chat Completions wrapper.

02

Nested parameters

Infer object, array, string, integer, number, boolean, and null nodes recursively.

03

Strict-ready objects

Generated object schemas include required lists and additionalProperties false.

04

Local deterministic output

Build a reviewable schema without sending the sample to an OpenAI model.

Useful answers

Questions about JSON to OpenAI Function Schema

Practical details about input, output, privacy, limits, and the best way to use this tool.

01 What is the difference between the two output formats?

The Responses API uses a flattened function tool object. Chat Completions places name, description, parameters, and strict inside a nested function object.

02 Does this call the OpenAI API?

No. It transforms the sample locally into JSON and does not execute a model request or function call.

03 What does strict mode change?

The generated wrapper sets strict: true. OpenAI strict function calling expects a compatible parameter schema, including required properties and additionalProperties: false for object schemas.

04 Are all generated properties required?

Yes. The generator cannot infer optionality from one example. With strict mode enabled, every property must remain in required; represent an optional value with a nullable type. With strict disabled, you may remove optional names from required.

05 How are empty or mixed arrays handled?

An empty array provides no item type. A non-empty array uses its first item as the initial item schema, so mixed arrays require manual editing.

06 Can the tool infer property descriptions or enum values?

No. Add descriptions and complete allowed-value rules manually so the model receives meaningful argument guidance.

07 What happens when the sample root is not an object?

The inferred value is wrapped in an object property named value because function arguments use an object parameter schema.

08 Does generated JSON guarantee a correct function call?

No. You must still send the correct API request, execute returned calls in your application, validate arguments, handle errors, and return tool results.

Learn JSON

Read the complete JSON Guide

Learn JSON objects, arrays, value types, validation, formatting, parsing, API workflows, and common syntax errors.

  • Objects, arrays, and values
  • Validation and formatting
  • API and parsing workflows
Read guide Practical explanations and examples

Examples

Responses API function tool

The Responses API format places name, description, parameters, and strict beside type.

Input
Sample JSON: {"location":"Kyiv","units":"celsius"}
Name: get_weather
Format: Responses API
Strict: enabled
Output
{
  "type": "function",
  "name": "get_weather",
  "description": "Get the current weather for a location",
  "parameters": {
    "type": "object",
    "properties": {
      "location": {"type": "string"},
      "units": {"type": "string"}
    },
    "required": ["location", "units"],
    "additionalProperties": false
  },
  "strict": true
}

Chat Completions function wrapper

Chat Completions nests the function definition inside the function property.

Input
Sample JSON: {"order_id":"ord_42","include_items":true}
Name: get_order
Format: Chat Completions
Strict: enabled
Output
{
  "type": "function",
  "function": {
    "name": "get_order",
    "description": "Generated function schema",
    "parameters": {
      "type": "object",
      "properties": {
        "order_id": {"type": "string"},
        "include_items": {"type": "boolean"}
      },
      "required": ["order_id", "include_items"],
      "additionalProperties": false
    },
    "strict": true
  }
}

Infer nested parameter types

Nested objects are recursive, while an array item schema is inferred from the first item.

Input
{
  "customer": {"id": "cus_42", "vip": true},
  "items": [{"sku": "A-10", "quantity": 2}]
}
Output
customer → object
customer.id → string
customer.vip → boolean
items → array
items[0].sku → string
items[0].quantity → integer

Responses API and Chat Completions formats

Both formats describe a tool with type: function, a programmatic name, a description, and a JSON Schema under parameters. The Responses API accepts these function fields directly on the tool object. Chat Completions uses a wrapper with the definition inside function. Select the format used by the endpoint and SDK code you will actually call.

The tool name identifies the application function; the description helps the model decide when that function is appropriate. Keep descriptions precise and distinguish tools that perform similar actions.

How JSON values become parameters

A sample object becomes an object parameter schema. Property names are preserved and values provide initial JSON types. Nested objects are inferred recursively. Integers remain integer, decimals become number, booleans remain boolean, and strings remain string. A scalar or array root is wrapped in a property named value.

Each object receives additionalProperties: false, and every observed property is added to required. This mirrors a closed sample, not necessarily the complete business contract.

Strict function calling and required fields

With strict enabled, OpenAI uses schema-constrained function arguments. The schema must conform to the supported strict-mode subset. Closed object schemas and explicit required lists are important parts of that structure. If strict is disabled, generated arguments should still be validated by your application before execution.

Optional and nullable are different concepts. Optional controls whether a property must appear; nullable controls whether its value may be null. A single sample cannot infer either intention reliably. Edit required arrays and type unions based on the real contract.

Inference limitations and edge cases

The generator does not infer descriptions, formats, enum choices, defaults, numeric ranges, string patterns, array length rules, alternative object shapes, or recursive references. An empty array has no evidence for items. A mixed array is represented using its first item. A null sample identifies only null and does not reveal the intended non-null type.

The output does not make an API request, select a model, invoke the function, verify permissions, or execute application code. Function arguments are model output and must be validated before they reach databases, files, networks, payment systems, or other sensitive operations.

Review before integration

Generate the initial wrapper, then add field descriptions and real constraints. Validate supported schema rules with JSON Schema Validator. Compare the provider-neutral MCP shape using MCP Tool Schema Generator and inspect an MCP definition with MCP Schema Validator. Test valid, missing, extra, nullable, and boundary arguments against the exact OpenAI endpoint and SDK version used by the application.

Tool definitions contribute to request size. Estimate the completed schema with AI Token Counter, then project representative request volume with AI Token Cost Calculator.

Official OpenAI and JSON Schema references

Review the current OpenAI function calling guide and JSON Schema Draft 2020-12 before shipping a production integration.