Code Beautifier

Code Beautifier API

Development

Format and beautify your code, JSON, XML, and other formats with customizable options.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

100 requests per minute

Endpoints

1 endpoint available

Overview

The Code Beautifier API formats and beautifies code using Prettier with extensive customization options.

Supported Languages

  • JSON
  • HTML
  • XML (uses HTML parser)
  • JavaScript
  • TypeScript
  • CSS
  • Markdown
  • YAML
  • Auto-detect (based on content)

Use Cases

  • Format code before committing to repositories
  • Standardize code style across projects
  • Beautify minified or compressed code
  • Integrate code formatting into CI/CD pipelines

Endpoints

POST
/v1/tools/code-beautifier
Format and beautify code with customizable options

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
code
string
Required
The code to format
language
string
OptionalLanguage: "auto", "json", "html", "xml", "javascript", "typescript", "css", "markdown", "yaml" (default: "auto")
options
object
OptionalFormatting options
options.printWidth
number
OptionalLine width (default: 80)
options.tabWidth
number
OptionalSpaces per indentation level (default: 2)
options.useTabs
boolean
OptionalUse tabs instead of spaces (default: false)
options.semi
boolean
OptionalAdd semicolons (default: true)
options.singleQuote
boolean
OptionalUse single quotes (default: false)
options.trailingComma
string
OptionalTrailing commas: "none", "es5", "all" (default: "es5")
options.bracketSpacing
boolean
OptionalSpaces in object literals (default: true)
options.arrowParens
string
OptionalArrow function parens: "avoid", "always" (default: "avoid")
options.proseWrap
string
OptionalProse wrapping: "always", "never", "preserve" (default: "preserve")
options.htmlWhitespaceSensitivity
string
OptionalHTML whitespace: "css", "strict", "ignore" (default: "css")

Response Example

{
  "success": true,
  "data": {
    "formattedCode": "{\n  \"name\": \"example\",\n  \"version\": \"1.0.0\"\n}\n",
    "language": "json",
    "inputLength": 35,
    "outputLength": 42
  }
}

Error Codes

400
Bad Request - Missing code or invalid syntax
401
Unauthorized - Invalid or missing API key
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

curl -X POST https://api.opentools.ca/v1/tools/code-beautifier \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "{"name":"example","version":"1.0.0"}",
    "language": "json",
    "options": {
      "tabWidth": 2,
      "printWidth": 80
    }
  }'

Ready to get started?

Create an API key to start using the Code Beautifier API.