← Shuffle JSON
Your token

Shuffle JSON API

Reading, checking, shuffling and every export run free in the browser and need no API. The API is for the one metered step: send the key names of a JSON file (with counts, value types and a few short example values), get back which keys are the same field under another name, which are notes or leftovers, and which are real fields of their own.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "match_keys".

taskWhat it doesReply
match_keysDecides every key that only some records have: rename it to another key in the file, leave it out of the check, or keep it as its own field. Never invents a key name.One JSON object

Input fields

FieldTypeMeaning
taskstring"match_keys"
keysstringJSON text: a list of {"key", "records", "types", "samples"}, one per key, at most 150, keys missing from some records first. types uses text, number, true/false, null, list, object; samples holds up to 3 non-empty values clipped to 40 characters.
factsstringJSON text: records, first_record_keys, uneven_keys (keys missing from at least one record), keys_sent, keys_total.

The reply

job.output.output is JSON text: {"task": "match_keys", "renames": [{"from", "to", "why"}], "ignore": [{"key", "why"}], "keep": [{"key", "why"}]}. Every uneven key is decided once: as a from, as a to, in ignore or in keep. Reason words: renames case, separator, spelling, abbreviation, synonym, plural, language; ignore comment, metadata, debug, empty; keep optional, different. If the balance ran low, truncated is true and the object may stop early; the page keeps the entries that arrived complete.

Worked example

Input (input.json), for the page's Messy contacts example:

{
  "task": "match_keys",
  "keys": "[{\"key\":\"email\",\"records\":6,\"types\":[\"text\"],\"samples\":[\"ana@example.com\",\"ben@example.com\",\"dev@example.com\"]},{\"key\":\"phone\",\"records\":7,\"types\":[\"text\"],\"samples\":[\"+34 600 111 222\",\"+44 7700 900123\",\"+33 6 12 34 56 78\"]},{\"key\":\"city\",\"records\":7,\"types\":[\"text\"],\"samples\":[\"Madrid\",\"Leeds\",\"Lyon\"]},{\"key\":\"e-mail\",\"records\":1,\"types\":[\"text\"],\"samples\":[\"chloe@example.com\"]},{\"key\":\"_note\",\"records\":1,\"types\":[\"text\"],\"samples\":[\"met at the trade show\"]},{\"key\":\"telephone\",\"records\":1,\"types\":[\"text\"],\"samples\":[\"+91 98765 43210\"]},{\"key\":\"Email\",\"records\":1,\"types\":[\"text\"],\"samples\":[\"emma@example.com\"]},{\"key\":\"nickname\",\"records\":2,\"types\":[\"text\"],\"samples\":[\"Em\",\"Gracie\"]},{\"key\":\"City\",\"records\":1,\"types\":[\"text\"],\"samples\":[\"Hong Kong\"]},{\"key\":\"name\",\"records\":8,\"types\":[\"text\"],\"samples\":[\"Ana Torres\",\"Ben Okafor\",\"Chloe Martin\"]}]",
  "facts": "{\"records\":8,\"first_record_keys\":[\"name\",\"email\",\"phone\",\"city\"],\"uneven_keys\":[\"email\",\"phone\",\"city\",\"e-mail\",\"_note\",\"telephone\",\"Email\",\"nickname\",\"City\"],\"keys_sent\":10,\"keys_total\":10}"
}

Reply:

{
  "task": "match_keys",
  "renames": [
    {
      "from": "e-mail",
      "to": "email",
      "why": "separator"
    },
    {
      "from": "Email",
      "to": "email",
      "why": "case"
    },
    {
      "from": "telephone",
      "to": "phone",
      "why": "synonym"
    },
    {
      "from": "City",
      "to": "city",
      "why": "case"
    }
  ],
  "ignore": [
    {
      "key": "_note",
      "why": "comment"
    }
  ],
  "keep": [
    {
      "key": "nickname",
      "why": "optional"
    }
  ]
}

On the page, the renames are applied to the shuffled copy and the records are checked again.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://shuffle-json.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"shuffle-json"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "match_keys", "keys": "[...]", "facts": "{...}"}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="shuffle-json:match_keys:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: renames, ignore, keep
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: shuffle-json:match_keys:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json