Forms · Glossary

What is a JSON payload?

A JSON payload is the data carried in the body of an HTTP request or response, written in JavaScript Object Notation. It is the part that matters to the receiving program, as opposed to the headers and address around it. JSON arranges that data as named values, lists and nested objects in plain text.

Anyone connecting a form to another system ends up reading one of these, usually while working out why a value landed in the wrong place. Knowing how the structure fits together turns that from guesswork into a two minute check.

· Co-founder

5 min read · Published

Answers keyed by label or by field id
QuestionKeyed by labelKeyed by field id
What the key looks likeThe question as the respondent saw it, such as Work emailA generated identifier with no meaning to a person
Readable in a logYesOnly with a lookup
Survives a reworded questionNo, the key changes with the labelYes
Two questions with the same labelCollapse into one key, so one answer is lostStay separate
Best forEmails, logs and quick automationsMapping into a database or CRM

The pieces JSON is built from

The format is defined in RFC 8259, and it is small enough to learn in one sitting. There are four primitive types, strings, numbers, booleans and null, and two structured types, objects and arrays. An object is an unordered collection of name and value pairs wrapped in braces; an array is an ordered list wrapped in square brackets. Values can nest, so an object can hold arrays of objects as deep as needed. Two rules from the standard catch people out. The names within an object should be unique, and when they are not, different programs behave differently. And JSON exchanged between systems must be encoded as UTF-8, which is why a mangled accented name usually points at an encoding setting rather than at the form.

Payload, headers and envelope

An HTTP request has an address, a set of headers and a body. The payload is the body. Headers describe it, most importantly the content type, which for JSON is application/json, and sometimes a signature proving who sent it. Inside the body, well designed payloads use an envelope: an outer object that says what kind of event this is and when it happened, with the record itself nested one level down. That lets one receiving endpoint handle several event types by reading the outer fields first, and it leaves room to add information later without breaking programs that only read the parts they already know. The word payload itself comes from shipping, where it means the cargo as distinct from the vehicle, and the analogy holds: the headers and the connection exist only to get the body to the right place intact.

A form submission, annotated

Take a demo request form from a fictional software company, Crateline. When somebody submits it, the webhook body is one object. Its event is form_submission, so the receiver knows what happened. Its timestamp records when. Its form object carries the form's id, title and slug, so one endpoint can serve several forms. Its response object carries the response id, then two maps of the same answers. In data, each key is a question label, so Work email points to the address the person typed. In raw_data, each key is the field's internal id, pointing to the same value. The answers are identical; only the keys differ, which is the whole reason both exist.

Reading a payload safely

Parse the body with a JSON parser, never by evaluating it as code and never by searching the raw text for a phrase. Check the event name before acting, then check that each value has the type you expect, because a number can arrive as a string and a checkbox answer can arrive as a list. Treat a missing key and an empty value as the same thing, since different senders represent an unanswered question differently. Do not rely on the order of keys, because the standard defines objects as unordered. Finally, keep a copy of the raw body for anything important, since it is the only record of what was actually received.

Where labels and ids cause trouble

The common failure is an automation built on labels. It works perfectly until somebody fixes a typo in a question, at which point the key changes and the receiving system quietly stops finding the answer. Building on field ids avoids that, at the cost of needing a lookup to know which id is which question. The second failure is two questions with the same label, such as two fields both called Phone. In this form builder's webhook the data map is built by label, so the second answer overwrites the first in data, while raw_data keeps both. Distinct labels solve it before it starts. A useful habit is to keep a small mapping table on the receiving side that pairs each field id with the label it had when the automation was built, so a later rename shows up as a mismatch you can see rather than a value that silently stops arriving.

Questions people ask

Is JSON the same as a JavaScript object?

No, though the syntax is related. JSON is a text format with stricter rules: names must be in double quotes, there are no comments, no trailing commas and no functions. Most languages can turn JSON text into their own objects and back, which is why it became the default for data passed between systems written in different languages.

How large can a JSON payload be?

The format sets no limit. Senders, receivers and the servers in between do, and those limits vary from a few hundred kilobytes to many megabytes. Forms rarely approach them with text answers alone. Files are the usual reason a payload grows, which is why most webhooks send a reference to an upload rather than the upload itself.

Why do numbers sometimes arrive in quotes?

Because the sender stored or passed the value as text. A form field that accepts digits may still send what the person typed as a string, particularly for things like postcodes and phone numbers, where leading zeros matter. Convert deliberately on the receiving side, and keep identifiers such as postcodes as strings so a leading zero is not lost.

What does null mean in a payload?

Null means the sender is saying explicitly that there is no value. It is different from an empty string, which is a value that happens to be blank, and from a missing key, where the sender said nothing at all. Receivers usually treat all three as no answer, but it is worth deciding that on purpose rather than by accident.

How do I read a payload that is one long line?

Paste it into a JSON formatter or open it in a code editor with formatting turned on, which will indent the nesting so the structure is visible. Be careful with online formatters when the payload contains personal information; a formatter built into your editor or browser developer tools keeps the data on your own machine.

Can a payload contain a file?

Only as text. A file can be encoded as a long base64 string inside a JSON value, which makes the payload roughly a third larger than the file, or it can be represented by a link or identifier the receiver uses to fetch it. The second approach is far more common, because it keeps payloads small and deliveries fast.

Make one with forms

The button opens the generator with this use case already described. Change the wording to match your own.

Create a form with OneCraft

Related questions

Step by step in the builder: Automate your form with add-ons, then Every form field and when to use it.

Sources

Written and checked by the OneCraft team. Last checked .