function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ujwala Mane 17Ujwala Mane 17 

Why parameter from client side to server side passed using JSON format?

Hi i have a doubt,

when we pass parameter from client side to server side, we specify it in JSON format in setParams or when we send list or map it is converted into JSON while sending.. So why it is so??
Similarly when we return parameter from apex to client side response we recived in JSON format.. so why is that??

Please help me to understand this..
It's because of Lightning Framework. Platform expects and sends in JSON.

AuraEnabled Annotation in Salesforce
The @AuraEnabled annotation enables client- and server-side access to an Apex controller method. Providing this annotation makes your methods available to your Lightning components (both Lightning web components and Aura components). Only methods with this annotation are exposed.

Passing Data to an Apex Controller
Use action.setParams() in JavaScript to set data to pass to an Apex controller.
The request payload includes the action data serialized into JSON.

Returning Data from an Apex Server-Side Controller
Return results from a server-side controller to a client-side controller using the return statement. Results data must be serializable into JSON format.
When an instance of an Apex class is returned from a server-side action, the instance is serialized to JSON by the framework.

Magulan Duraipandian