---
title: "Convert Expression To Json"
method: POST
path: "/variables/convert-expression-to-json"
tags: ["variables"]
---

# Convert Expression To Json

`POST /variables/convert-expression-to-json`

Convert a PyBaMM expression string to JSON-serialized format.

The expression can use:
- CoupledVariable("Variable Name") for model variables
- Parameter("Parameter Name") for model parameters
- InputParameter("Input Name") for optimization inputs
- Standard math operations (+, -, *, /, **)

Example expression:
    CoupledVariable("Voltage [V]") - Parameter("Target Voltage")

Parameters
----------
request : ExpressionToJsonRequest
    Request body containing the expression string

Returns
-------
ExpressionToJsonResponse
    Response with the JSON-serialized PyBaMM symbol

## Request body

- ExpressionToJsonRequest — Request body for converting PyBaMM expression string to JSON.
  - `expression` string, required

## Response `200`

Successful Response

- ExpressionToJsonResponse — Response body with JSON-serialized PyBaMM symbol.
  - `value` object, required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/ionworks/apis/fastapi.md) · [All operations](https://skmtc.dev/ionworks/apis/fastapi/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/ionworks/fastapi/revisions/7337a3cbdaf2/schema)
