I am using a custom form to submit data to a remote ReST API which accepts a JSON POST.
I have set up a ReST submission action and added the template for the JSON request to the request body, then replaced the appropriate values with %response_ keywords and this works ok.
Is this possible ?
Fairly certain the answer is “no”, JS can only be run on the response.
Yes, it is possible. you could process all of the form data through a SSJS process and do all your data manipulation there and then send that in the POST data. Is that what you mean?
Example would be to use %globals_asset_contents_raw:1234^run_ssjs%, where asset ID 1234 is a standard page that just has SSJS in it that access the form data using %globals_post% keyword and then you can process that data in JS and then use the print() function to print whatever JSON you need.