How to use JSON prompts with AI prompt

This guide provides information on how to use JSON to run AI prompts in the command shell. This method works on cmd.exe, powershell in Windows and can also be used in Linux bash or using the shell on your Mac.

What is JSON?

JSON is a lightweight data-interchange format that is easy for humans to read and write, and simple for machines to parse and generate. It is commonly used to transmit data between a server and a client in web applications.

Data is stored using key-value pairs. A key is like a label, and the value is the information connected to the label. These key-value pairs can be grouped inside objects, marked with {} , and lists, marked with [].

Why is this important?

The Ozeki AI Server uses JSON format to send and receive our AI Prompts as well. Ozeki AI Prompt converts your basic prompt to JSON format, which makes testing and simple interactions fast and easy, but you also have the option to send your prompts in JSON format directly.

AI JSON Example:

{
    "model": "GGUF_Model_1",
    "messages": [
        {
            "role": "system",
            "content": "Transcript of a conversation between the User and an 
            Assistant. Assistant is a friendly, reliable, and highly knowledgeable 
            assistant, known for being helpful, empathetic, and honest. Assistant 
            consistently delivers prompt, clear, and accurate responses,     
            excelling in writing and problem-solving, ensuring the User's 
            requests are addressed with precision and care!"
        },
    	{
            "role": "user",
            "content": "Hello"
        },
    	{
            "role": "assistant",
            "content": "How may I help you today?"
        },
   	 	{
            "role": "user",
            "content": "Where is London?"
        }
    ],   
}

How to use JSON prompts with AI Prompt (Easy steps)

To use JSON prompts with AI Prompt, follow these steps:

  1. Requirements
  2. Configuration
  3. JSON Prompt from the Command Prompt
  4. Create and read JSON prompt from file

Requirements

Before continuing with this guide, make sure Ozeki AI Prompt is installed on your computer.

If you haven't downloaded AI Prompt yet, check out AI prompt to learn how to setup AI Prompt on your computer.

Configuration

Make sure to use the following configuration to successfully send a JSON prompt:

JSON

To enable JSON mode, use the -j option

Model

If a model is specified when using JSON prompt, it will be ignored.

How to send a JSON prompt with AI Prompt (Video tutorial)

In this short video, you will see an example of sending JSON prompt through the command line, with the help of echo command.

Video 1 - Send JSON prompt from the command line

How to send a JSON prompt with AI Prompt

A JSON prompt must be specified through the standard input. To specify a JSON prompt, use the echo command to print the JSON to the standard input:

::Change the credentials to yours
echo {"model":"GGUF_Model_1","messages":[{"role":"user","content":"Where is Budapest"}]} | aiprompt.exe -u user -p pass -j

JSON prompt from the command line
Figure 1 - JSON prompt from the command line

The output will be the full JSON response sent by the HTTP AI API. The received data contains more information about the processing of the prompt, which might be useful.

Output:

{
  "id": "chatcmpl-XPTKXQEAABBFYTJUCQKYKAQGPCLBR",
  "object": "chat.completion",
  "created": 1738079682,
  "model": "GGUF_Model_1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Budapest is the capital and largest city of Hungary, located in the north-central part of the country. It is situated on both banks of the Danube River, with Buda on the west bank and Pest on the east bank. The city is known for its rich history, cultural heritage, and stunning architecture.",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0,
    "completion_tokens_details": {
      "reasoning_tokens": 0
    }
  },
  "system_fingerprint": "fp_f85bea6784"
}

How to create and read a JSON prompt from a file (Video tutorial)

This video will demonstrate how to create a JSON file with Notepad, and how to read it with the type command to provide it to AI Prompt using standard IO.

Video 2 - Create and read JSON prompt from file

How to create and read a JSON prompt from a file

Open the File Explorer at the location of your AI Prompt installation.

Open File Explorer
Figure 2 - Open File Explorer at the location of AI Prompt

To create a JSON File, you can use Notepad. To open a Notepad, type notepad into the File Explorer's address bar and press Enter.

Open a Notepad
Figure 3 - Open a Notepad

Paste the JSON prompt into the newly opened Notepad. You can also customize the JSON prompt in Notepad to your liking.

Contents of prompt.json:

{
    "model":"GGUF_Model_1",
    "messages":[ 
       {
          "role":"user",
          "content":"Where is Budapest?"
       },
       {
         "role":"assistant",
         "content":"Budapest is the capital city of Hungary, located in Central Europe. It sits on both sides of the Danube River, with Buda on the west bank and Pest on the east. Budapest is known for its stunning architecture, historic sites, and vibrant culture, making it a popular destination for tourists."
       },
       {
         "role":"user",
         "content":"Tell me the three most visited tourist attraction in Budapest"
      }
    ]
}

Figure 4 - Paste the JSON prompt into notepad

Save the json file by selecting the File menu, and clicking on the Save as.. option.

Save the prompt
Figure 5 - Save the prompt

After clicking Save as..., the Save as dialog is opened. Set the save location to the path to your AI Prompt installation. Enter the filename "prompt.json" in the input area labeled File name and select All Files in the dropdown menu labeled Save as type.

Enter filename and select all files
Figure 6 - Enter filename and select all files

Click the Save button to save the JSON file.

Save JSON file
Figure 7 - Save JSON file

At this point you have successfully created the JSON file, which you can confirm by looking at the File Explorer. To run AI Prompt, open Command Prompt by typing cmd into the address bar of the File Explorer, and press Enter.

Open Command Prompt
Figure 8 - Open Command Prompt

Use the type command to print the contents of the JSON file to the standard input. Run AI Prompt with the -j option to enable JSON mode.

Example command:

type prompt.json | aiprompt.exe -u user -p pass -j

Run AI Prompt
Figure 9 - Run AI Prompt

Output:

{
  "id": "chatcmpl-GNVXTNBNEMXTDCLKEHFGLHLVXPKST",
  "object": "chat.completion",
  "created": 1738074469,
  "model": "GGUF_Model_1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Certainly! Here are three of the most visited tourist attractions in Budapest:\n\n1. **Buda Castle**: Located on Castle Hill in Buda, this iconic fortress offers stunning views of the Danube River and the city. It houses several museums, including the Hungarian National Gallery and the Budapest History Museum.\n\n2. **Parliament Building**: Situated on the Pest side of the river, this impressive Neo-Gothic structure is one of Hungary's most recognizable landmarks. Visitors can take guided tours to explore its grand halls and learn about its history.\n\n3. **Széchenyi Thermal Bath**: Known as one of the largest and most beautiful spa complexes in Europe, it offers a variety of thermal pools, saunas, and wellness facilities. It's a perfect place to relax and unwind in a stunning architectural setting.",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0,
    "completion_tokens_details": {
      "reasoning_tokens": 0
    }
  },
  "system_fingerprint": "fp_f85bea6784"
}

Do I need programming skills to use JSON with Ozeki AI Prompt?

Not at all! JSON is highly intuitive and easy to learn, even for beginners. The guide provides clear examples and video tutorials to help you create and send JSON prompts.

Why should I bother with using JSON prompts instead of basic prompts?

JSON prompts offer more control, flexibility, and functionality. They allow you to structure complex instructions, include multiple messages, and provide detailed context for better AI responses. JSON prompts are reusable, scalable for automation, and their structured outputs make integration with other tools seamless. It’s the smarter choice for precision and efficiency in AI interactions!

Conclusion

This guide has walked you through every step, from understanding the basics of JSON to executing your first JSON prompt, with helpful examples and video tutorials along the way. Start experimenting, and take your AI Prompt solutions to the next level with the power of JSON!

More information