---
title: "KnapsackJSON"
description: "Benchmarks problems stored in your own file format, here knapsacks written as JSON."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cpbenchy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# KnapsackJSON

## What it does

Benchmarks problems stored in your own file format. This loader reads knapsack instances written as
JSON and builds the CPMpy model, inside the measured run, so building it is measured as `parse_s`, as
loading any other format is.

```json
{"capacity": 50, "items": [{"weight": 10, "value": 60}, {"weight": 20, "value": 100}]}
```

## Use it

```python
import cpbenchy

cpbenchy.run("examples/data/*.json", solvers=["ortools", "exact"], time_limit=60,
             loader="examples/loaders/knapsack_json.py:KnapsackJSON")
```

```sh
cpbenchy run examples/data/*.json -s ortools -s exact -t 60 --loader examples/loaders/knapsack_json.py:KnapsackJSON
```

Results record the loader, so the same instance loaded another way is another run.

## Implementation

Source: https://docs.cpbenchy.com/examples/knapsack-json/index.mdx
