Skip to content

Why does an apparently valid JSON file receive Send valid JSON when I submit it to the API?

A leading UTF-8 byte order mark is one possible reason a valid-looking JSON file fails before its values are validated. Inspect the actual request file's bytes rather than only its editor view. The current AISwapLab JSON reader decodes the received bytes as UTF-8 and passes the resulting string to JSON.parse; a leading BOM can fail that expression. Send network JSON without that preamble, preserving the intended JSON values.

TEST THE CUSTOMER API CONTRACTAISwapLab team · Editorial methodPublished 3 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Confirm the actual serialization problem; Write a clean network representation deliberately; Validate locally before another submission.
Workflow diagram: Confirm the actual serialization problem → Write a clean network representation deliberately → Validate locally before another submission. Read the article for evidence and limits.

The invisible prefix is outside the approved prompt text

RFC 8259 says network JSON senders must not add a BOM, while allowing parsers to ignore one. It does not require every parser to accept or reject it. Microsoft also documents different PowerShell file-encoding defaults by version: Windows PowerShell's UTF8 option includes a BOM, whereas newer versions support UTF8 without it. This is a serialization issue before schema interpretation, not the same operation as normalizing visually similar characters inside a parsed prompt.

What to do next

  1. 01

    Confirm the actual serialization problem

    Treat Send valid JSON as a parse symptom, not proof that a BOM is present. With a trusted local byte viewer, inspect the exact file intended for the request; EF BB BF before the opening JSON token identifies a UTF-8 BOM. Also check that the file is genuinely UTF-8 JSON rather than UTF-16, an HTML document or an escaped string containing another document. Use a harmless synthetic reproduction for support instead of exposing private request content.

  2. 02

    Write a clean network representation deliberately

    Use an editor or serializer setting explicitly documented as UTF-8 without BOM. In modern PowerShell, select the supported utf8NoBOM encoding where appropriate; do not assume Windows PowerShell 5.1 interprets the same encoding name or default identically. Choose a version-appropriate documented writer rather than globally changing every script's encoding settings. Preserve all intended JSON field values, then read the saved bytes back. Renaming the file or deleting an arbitrary visible character is not a reliable encoding repair.

  3. 03

    Validate locally before another submission

    Parse the final file with the same relevant decoding and JSON-parsing behavior, then apply the normal supported-field and size checks. A small fixture containing an ordinary object and a copy prefixed with the three BOM bytes can isolate the mechanism without contacting any provider. If a previous action was accepted or its outcome is uncertain, retain its original payload and recovery identity. Do not silently rewrite an already approved request and replay it as though it were unchanged.

A concrete example

Illustrative diagnosis: two files both display an empty object in an editor, but one begins with EF BB BF. The local parse check distinguishes them. Saving a separate UTF-8-without-BOM copy removes that specific transport preamble without changing the object's values. This example does not establish that every parse failure has this cause or that any production request was tested.

Before you call it ready

  • The raw prefix and actual encoding are inspected independently of the editor appearance.
  • The replacement network file preserves the intended JSON values without a BOM.
  • Local parsing precedes creation, and earlier uncertain actions retain their recovery identity.

When to stop or choose another method

Stop treating an invisible-prefix problem as a reason to buy credits, change models or normalize prompt text after approval. If the cleaned file still fails, investigate the next concrete syntax or contract error instead of deleting bytes indiscriminately.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation