> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.comet.com/docs/opik/llms.txt.

# Create dataset items from JSON file

POST http://localhost:5173/api/v1/private/datasets/items/from-json
Content-Type: multipart/form-data

Create dataset items from an uploaded JSON or JSONL file. JSON files must contain a top-level array of objects.
JSONL files contain one JSON object per non-blank line; multi-line JSON objects are not supported.
Reserved keys (id, source, description, tags, evaluators, execution_policy) are extracted into the
corresponding DatasetItem fields; all remaining keys form the item's data map and preserve their JSON types.
To link dataset items to specific traces or spans use the dedicated /items/from-traces or /items/from-spans endpoints.
Processing happens asynchronously in batches. With dataset versioning enabled, a supplied id acts as an upsert key.

Reference: https://www.comet.com/docs/opik/reference/rest-api/datasets/create-dataset-items-from-json

## Servers

- `http://localhost:5173/api` (Local server, default)
- `https://www.comet.com/opik/api` (Opik Cloud)

## Request

### Body (multipart/form-data)

This endpoint expects a multipart form.

- `file` (V1PrivateDatasetsItemsFromJsonPostRequestBodyContentMultipartFormDataSchemaFile, required)
- `dataset_id` (string, required)
- `format` (enum, required)

## Response

### 202

Accepted - JSON processing started

## Errors

### 400 Bad Request Error

Bad Request

- `code` (integer, optional)
- `message` (string, optional)
- `details` (string, optional)

## Examples

**Request**

```json
{
  "dataset_id": "string",
  "file": {},
  "format": "json"
}
```

**Response**

```json
{}
```

**SDK Code**

```python
import requests

url = "http://localhost:5173/api/v1/private/datasets/items/from-json"

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataset_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n{}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\njson\r\n-----011000010111000001101001--\r\n"
headers = {"Content-Type": "multipart/form-data; boundary=---011000010111000001101001"}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/datasets/items/from-json';
const form = new FormData();
form.append('dataset_id', 'string');
form.append('file', '{}');
form.append('format', 'json');

const options = {method: 'POST'};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:5173/api/v1/private/datasets/items/from-json"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataset_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n{}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\njson\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://localhost:5173/api/v1/private/datasets/items/from-json")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataset_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n{}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\njson\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://localhost:5173/api/v1/private/datasets/items/from-json")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataset_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n{}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\njson\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:5173/api/v1/private/datasets/items/from-json', [
  'multipart' => [
    [
        'name' => 'dataset_id',
        'contents' => 'string'
    ],
    [
        'name' => 'file',
        'contents' => '{}'
    ],
    [
        'name' => 'format',
        'contents' => 'json'
    ]
  ]
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("http://localhost:5173/api/v1/private/datasets/items/from-json");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dataset_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n{}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"format\"\r\n\r\njson\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation
let parameters = [
  [
    "name": "dataset_id",
    "value": "string"
  ],
  [
    "name": "file",
    "value": "{}"
  ],
  [
    "name": "format",
    "value": "json"
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/datasets/items/from-json")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```