---
title: "Do not use JSON.stringify to pass params to Apex"
url: "https://blog.beyondthecloud.dev/tips/do-not-use-json-stringify-to-pass-params-to-apex"
category: "LWC"
tags: "apex, performance, best-practices"
published: "2025-01-06"
---

# Do not use JSON.stringify to pass params to Apex

Serializing parameters before passing them to Apex is considered bad practice because it leads to unclean code and negatively impacts performance.

Do NOT use JSON.stringify to pass params to Apex

Serializing parameters before passing them to Apex is considered bad practice because it leads to unclean code and negatively impacts performance.

```apex
@AuraEnabled
public static void call(String serializedParam) {
    MyWrapper wrapper = (MyWrapper) JSON.deserialize(serializedParam, MyWrapper.class);
    // ...
}
```

```javascript
const params = {
    // ...
};

await call({
    serializedParam: JSON.stringify(params)
});
```

Apex data structures have corresponding equivalents in LWC that can be used directly. Please take a look at the table below for details.

APEX

LWC

Primitive Types e.g Boolean, String, Integer

Primitive Types

List<Type> e.g List<String>

Array [ ]

Custom Objects e.g Account, Custom__c

Object { }

Class e.g WrapperClass

Object { }

Map<Type, Type> e.g Map<String, String>

Object { }

Primitive Types

```apex
@AuraEnabled
public static void call(String stringParam, Integer integerParam) {
}
```

```javascript
await call({
    stringParam: 'Some String',
    integerParam: 42
});
```

List<Type>

```apex
@AuraEnabled
public static void call(List<String> myList) {
    // ...
}
```

```javascript
const stringArray = [
    'Some String 1',
    'Some String 2',
    'Some String 3',
];

await call({
    myList: stringArray
});
```

Custom Objects

```apex
@AuraEnabled
public static void call(Account account) {
    // ...
}
```

```javascript
const newAccount = {
    Name: 'Account Name'
};

await call({
    account: newAccount
});
```

Wrapper Class

```apex
public class MyWrapper {
    @AuraEnabled
    public String myString {get; set;}
    @AuraEnabled
    public Integer myInteger {get; set;}
}
```

```apex
@AuraEnabled
public static void call(MyWrapper myWrapper) {
    // ...
}
```

```javascript
const myWrapper = {
    myString: 'Some String',
    myInteger: 43
};

await call({
    myWrapper: myWrapper
});
```

Map<Type, Type>

```apex
@AuraEnabled
public static void call(Map<String, String> myMap) {
    // ...
}
```

```javascript
const myMap = {
    param1: 'Some String 1',
    param2: 'Some String 2'
};

await call({
    myMap: myMap
});
```
