Text Line Tools API

Sort, deduplicate, reverse, trim, number or wrap text lines through a single JSON endpoint.

Try the Text Line Tools API

POST /api/v1/text-line-tools/

Send request transmits this input to the API server. The online tool processes input in your browser.

Request parameters

ParameterTypeRequiredRules
textstringYesA line-separated list, at most 1000 lines. Maximum: 16384 code points.
operationstringNoOne line operation per request; shuffle is not included in this API. Values: sort, dedupe, reverse, empty, trim, number, affix. Default: "sort".
sortModestringNoSort by code point, natural order, code-point length or leading number. Values: alpha, natural, length, numeric. Default: "alpha".
descbooleanNoReverse the sort comparison. Default: false.
ignoreCasebooleanNoIgnore case for sorting and duplicate comparison. Default: false.
ddModestringNoKeep first occurrences, repeated values only or non-repeated values only. Values: unique, duplicates, singletons. Default: "unique".
trimComparebooleanNoTrim values only for duplicate comparison. Default: false.
trimModestringNoWhich side of a line to trim. Values: both, start, end. Default: "both".
startintegerNoFirst number for number operation. Default: 1. Range: -1000000–1000000.
sepstringNoSeparator after the line number. Default: ". ". Maximum: 20 code points.
padbooleanNoPad line numbers to a consistent width. Default: false.
prefixstringNoPrefix for affix operation. Default: "". Maximum: 100 code points.
suffixstringNoSuffix for affix operation. Default: "". Maximum: 100 code points.
skipBlankbooleanNoLeave blank lines unchanged when adding affixes. Default: false.

Response fields

A successful response is {"ok":true,"data":{…}}. These fields are inside data.

result · string
The converted text. Empty input can produce an empty result.
inCount · integer
Returned inCount. Minimum: 0.
outCount · integer
Returned outCount. Minimum: 0.

Clean a list without a spreadsheet

Each request applies one operation to a list and returns the resulting text plus input and output line counts. Chaining calls lets a script deduplicate, sort and number a list while preserving the individual rules of each step. Only options used by the selected operation affect the result. Unknown option names return 400 so typos are visible.

Line boundaries and ordering

LF, CRLF and CR separate lines. A final line terminator is not counted as an extra empty line, and output uses LF. Alphabetical sorting compares code points; natural sorting uses the English numeric collator. Sorting is stable for equal values. Numeric mode puts lines without a leading number after numeric lines. Requests with more than 1000 lines are rejected.

cURL, JavaScript and Python examples

Natural sort

Natural sorting compares embedded digit sequences numerically.

cURL
curl --fail-with-body --request POST 'https://www.base64.sh/api/v1/text-line-tools/' \
  --user-agent 'Base64.sh API example/1.0' --header 'Content-Type: application/json' \
  --data-raw '{"text":"file10\nfile2\nfile1","sortMode":"natural"}'
JavaScript
const response = await fetch("https://www.base64.sh/api/v1/text-line-tools/", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "text": "file10\nfile2\nfile1",
  "sortMode": "natural"
})
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
Python
import json
from urllib.request import Request, urlopen

payload = json.loads("{\n  \"text\": \"file10\\nfile2\\nfile1\",\n  \"sortMode\": \"natural\"\n}")
request = Request(
    "https://www.base64.sh/api/v1/text-line-tools/",
    data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    headers={"Content-Type": "application/json", "User-Agent": "Base64.sh API example/1.0"},
    method="POST",
)
with urlopen(request, timeout=15) as response:
    print(json.load(response))

Response · HTTP 200

{
  "ok": true,
  "data": {
    "result": "file1\nfile2\nfile10",
    "inCount": 3,
    "outCount": 3
  }
}

Remove duplicates

The first spelling is retained when comparison ignores case.

cURL
curl --fail-with-body --request POST 'https://www.base64.sh/api/v1/text-line-tools/' \
  --user-agent 'Base64.sh API example/1.0' --header 'Content-Type: application/json' \
  --data-raw '{"text":"Apple\napple\nPear","operation":"dedupe","ignoreCase":true}'
JavaScript
const response = await fetch("https://www.base64.sh/api/v1/text-line-tools/", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "text": "Apple\napple\nPear",
  "operation": "dedupe",
  "ignoreCase": true
})
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
Python
import json
from urllib.request import Request, urlopen

payload = json.loads("{\n  \"text\": \"Apple\\napple\\nPear\",\n  \"operation\": \"dedupe\",\n  \"ignoreCase\": true\n}")
request = Request(
    "https://www.base64.sh/api/v1/text-line-tools/",
    data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    headers={"Content-Type": "application/json", "User-Agent": "Base64.sh API example/1.0"},
    method="POST",
)
with urlopen(request, timeout=15) as response:
    print(json.load(response))

Response · HTTP 200

{
  "ok": true,
  "data": {
    "result": "Apple\nPear",
    "inCount": 3,
    "outCount": 2
  }
}

Invalid request example

{
  "text": 123
}

HTTP 400

{
  "ok": false,
  "error": {
    "code": "INVALID_INPUT",
    "message": "text must be a string."
  }
}

Limits and error handling

Requests require Content-Type: application/json and a UTF-8 JSON object. The body limit is 32 KiB (32,768 bytes), text fields allow up to 16,384 Unicode code points unless a smaller limit is listed, and responses are limited to 256 KiB. Unknown parameters and unpaired Unicode surrogates in parameter strings are rejected. Send inputs in the request body, not query parameters.

Anonymous access is limited to approximately 60 POST requests per minute per IP address, shared across endpoints in each Cloudflare location. Shared networks share the allowance. Counters are eventually consistent, not a guaranteed global quota. On HTTP 429, wait for the Retry-After interval before retrying; avoid immediate retry loops.

Programmatic clients should send an identifying User-Agent, as shown in the cURL and Python examples. Browser fetch supplies its own header. Cloudflare may reject a generic or missing agent before the API runs; an edge-generated 403 can be plain text or HTML rather than the JSON envelope. See Cloudflare error 1010.

400 · Invalid input
Malformed JSON, missing fields, unsupported options or invalid encoded text. Correct the input before retrying.
403 · Edge request blocked
Check the User-Agent and the Cloudflare error response before retrying.
404 · Unknown endpoint
Use a documented /api/v1/{tool}/ endpoint.
405 · Method not allowed
Use POST. OPTIONS is supported for browser CORS requests.
413 · Size limit exceeded
Reduce the request size or the generated output.
415 · Unsupported media type
Set Content-Type: application/json.
429 · Rate limited
Wait at least the Retry-After number of seconds.
500 / 503 · Service unavailable
Retry later with bounded backoff. Availability is not guaranteed.

API data processing

API inputs are sent over HTTPS and processed in memory by a Cloudflare Worker. The application does not persist submitted text or deliberately log request bodies, and API responses use Cache-Control: no-store. Cloudflare may process network metadata under its own policies. For local processing, use the corresponding browser tool. See the privacy policy.