Patch datafile
patch_datafileEdit an EXISTING datafile's JSON in place without resending the whole document — the right tool for changing one field of a large datafile, appending a blog post to a list, or fixing a word in a long string. Apply ordered operations (set / remove / replace_in / test) addressed by a dot-path from the document root (e.g. 'posts[slug=hello].title', or 'posts[-]' with op 'set' to APPEND). Pass values as raw JSON — the platform owns the escaping. For a SMALL change to a LARGE string use replace_in (find→replace, must match exactly once) so you send a few bytes. For a large NEW value send it with value_encoding=base64 (or gzip+base64) plus a value_sha256, so transcription damage is rejected instead of silently written. This is SAFER than update_datafile, not just cheaper: the patch is applied to the content it just read and the write is gated on that exact content, so a concurrent write is always reported rather than clobbered — no read-modify-write race, even with no arguments from you. The result is validated against the datafile's bound schema before it lands; a patch that would break the schema is rejected and nothing is written. Property order is preserved: untouched parts of the document come back byte-identical, so the change you make is the whole diff. Set republish=true to push the result to the CDN path it was last published at.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| slug | No | the datafile slug (provide this or datafile_id) | |
| republish | No | after patching, re-publish to the CDN path this datafile was last published at. Errors if it has never been published (use publish_datafile with an explicit public_path first); the patch still applied. | |
| operations | Yes | ordered edits applied to the datafile's stored JSON | |
| datafile_id | No | the datafile id (provide this or slug) | |
| expected_content_sha256 | No | the content_sha256 from the get_datafile you built these operations from. If the stored content has moved since, the patch is REFUSED — nothing is applied, nothing is written. REQUIRED when any path addresses an array element by numeric index (items[2]), because that is a claim about the document's current shape whose failure is otherwise SILENT: if an element shifted, the write is still internally consistent and edits the wrong one. Optional for self-locating paths — items[slug=my-post], items[-] (append), or a plain key — which mean the same thing whatever the document holds, so appending to a large collection needs no read. Independently of this argument, the write is always gated on the content the patch itself just read, so it can never clobber a concurrent write. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datafile | Yes | ||
| public_url | No |