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

# Adding New Field to REST Body Using JsonSlurper

> Adding new field to REST request body and using existing fields with Groovy script using JsonSlurper

## Groovy Script

```groovy theme={null}
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

def jsonSlurper = new JsonSlurper()
def jsonMessage = jsonSlurper.parseText(requestBodyTextFromClient)

jsonMessage.put("tamAd", jsonMessage.ad + " Api Management")

requestBodyTextToTargetAPI=JsonOutput.toJson(jsonMessage)
```

## Example

### Original Request

```json theme={null}
{
  "ad": "Apinizer"
}
```

### New Request

```json theme={null}
{
  "ad": "Apinizer",
  "tamAd": "Apinizer Api Management"
}
```

## Explanation

This script performs the following operations:

1. **JSON Parse**: JSON message coming from request body is parsed
2. **Field Addition**: A new field (`tamAd`) is added using existing fields
3. **JSON Creation**: Updated JSON message is created

<Note>
  This script should be run on the request line (Request Policy) because it uses the `requestBodyTextFromClient` and `requestBodyTextToTargetAPI` variables.
</Note>
