---
title: "Multipart form to JSON | WebhookRelay"
meta:
  "og:description": "Parsing multipart form data inside the Webhook Relay Function"
  "og:title": "Multipart form to JSON"
  description: "Parsing multipart form data inside the Webhook Relay Function"
---

![Stripes](https://webhookrelay.com/docs/webhooks/functions/multipart-form-data/images/stripes.svg)

Documentation

**Fundamentals**

# **Multipart form to JSON**

Parsing multipart form data inside the Webhook Relay Function

Webhook Relay detects multipart/formdata requests and automatically parses them so your function can use it. Parsed form data can be accessed through `r.RequestFormData` / `r.formData` variable. You can use Webhook Relay to receive a form and convert it into any kind of JSON that can be sent to another API.

## [Using decoded values](#using-decoded-values)

For example if the payload fragment looks like this:

```
...
--------------------------5683f7544dff7b07
Content-Disposition: form-data; name="username"

John
--------------------------5683f7544dff7b07
...
```

Then to get `username` value (which is `John`) you will need to:

```
// values can be accessed through 'r.formData' object. Since
// there can be multiple values for each key, you also need to
// specify that it's the first element of the list (0-indexed):
const username = r.formData.username[0]
const firstName = r.formData.first_name[0]

// transforming form data into JSON
const jsonPayload = {
  username: username,
  first_name: firstName
}

const encodedPayload = JSON.stringify(jsonPayload)

r.setBody(encodedPayload)
```

```
-- import "json" package when working with JSON
local json = require("json")

-- values can be accessed through 'r.RequestFormData' object. Since
-- there can be multiple values for each key, you also need to
-- specify that it's the first element of the list:
local username = r.RequestFormData.username[1]
local first_name = r.RequestFormData.first_name[1]

-- transforming form data into JSON
local json_payload = {
  username = username,
  first_name = first_name
}

local encoded_payload, err = json.encode(json_payload)
if err then error(err) end

r:SetRequestBody(encoded_payload)
```

## [Prerequisites](#prerequisites)

For the decoding to work, Webhook Relay expects a header `Content-Type` that includes `multipart/form-data` and the boundary.

Did this page help you?