Skip to content

Format Code

Standard · 1 credit

Format source code using the right formatter for the language — Biome for JavaScript, TypeScript, CSS, and JSON; gofmt for Go.

POST /api/format-code

FieldTypeRequiredDefaultDescription
languagestringYesjavascript (or js), typescript (or ts), jsx, tsx, json, css, go
codestringNo*Source code to format (single-file mode)
filesobjectNo*Map of filename → source code (multi-file mode)
fragmentbooleanNofalseTreat input as a code fragment rather than a complete file
config.indent_widthintegerNoIndentation width in spaces
config.semicolonsbooleanNoInclude semicolons (JS/TS)
config.use_tabsbooleanNoUse tabs instead of spaces

*Provide either code (single file) or files (multiple files), not both.

FieldTypeDescription
formattedstringFormatted code (single-file mode)
filesobjectMap of filename → formatted code (multi-file mode)
language_detectedstringLanguage used for formatting
changes_madebooleanWhether the code was modified
Terminal window
curl -X POST https://morso.dev/api/format-code \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"language": "typescript", "code": "const x=1;const y=2;function add(a:number,b:number){return a+b}"}'
{
"formatted": "const x = 1;\nconst y = 2;\nfunction add(a: number, b: number) {\n\treturn a + b;\n}\n",
"language_detected": "typescript",
"changes_made": true
}
Terminal window
curl -X POST https://morso.dev/api/format-code \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"language": "typescript", "files": {"index.ts": "const x=1", "utils.ts": "export const add=(a:number,b:number)=>a+b"}}'
{
"files": {
"index.ts": "const x = 1;\n",
"utils.ts": "export const add = (a: number, b: number) => a + b;\n"
},
"language_detected": "typescript",
"changes_made": true
}
Terminal window
curl -X POST https://morso.dev/api/format-code \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"language": "javascript", "code": "const x = 1", "config": {"use_tabs": true, "semicolons": false}}'
{
"formatted": "const x = 1\n",
"language_detected": "javascript",
"changes_made": true
}