What Is JSON? Syntax, Data Types, and API Examples

What Is JSON?

Scrapeless Scraping API returns structured data from supported web sources for applications that need machine-readable results.

JSON is a text format for representing structured data. An object groups named values, while an array keeps values in order. The format is small enough to inspect in a text editor and precise enough for software in different languages to exchange the same basic structures. Its name comes from JavaScript Object Notation, but JSON is a data format rather than a JavaScript program.

A JSON response is useful only when the reader knows what the fields mean. A product record with a price, currency, and availability is more informative than an unlabelled number. This guide explains the grammar, shows how JSON fits into an HTTP exchange, and separates syntax validity from the harder problem of trustworthy data.

How JSON Represents Data

JSON has six kinds of values: object, array, string, number, boolean, and null. The JSON format specification defines their grammar. An object is written with braces and consists of name and value pairs. An array is written with brackets and contains an ordered sequence of values. The same array can contain several JSON value types, although an application schema may impose tighter rules.

Strings use double quotation marks. Within a string, quotation marks, backslashes, and certain control characters need escaping. Numbers use a decimal grammar; JSON has no built-in representation for values such as infinity or an undefined JavaScript value. The words true, false, and null are lowercase literals. A parser can reject a document because of a single trailing comma or an unquoted property name.

For example, a hypothetical response can contain an object named item with a string title, a numeric price, a boolean inStock value, and an array of tags. The outer shape says which fields travel together; the values say what was observed. JSON does not prescribe a currency, time zone, or business definition for those fields. The producer and consumer still need a contract that gives each name a stable meaning.

What a JSON Document Can and Cannot Guarantee

Valid JSON proves that the text follows a grammar. It does not prove that a required field exists, a price is current, or a URL is safe to open. A parser can accept an object whose fields are all wrong for the operation at hand. After parsing, validate the expected shape, value ranges, and identifiers before feeding the data into a user interface or downstream job.

Duplicate object names are particularly awkward. The format describes names within an object as ideally unique, yet parsers may handle repeats differently. One implementation can keep the last value while another reports an error. If a security decision depends on a field, do not let two conflicting copies of that name silently pass through different layers of the system.

JSON also does not carry a native date type, binary blob, or schema declaration. Applications commonly encode times as strings and binary content through an agreed representation, but those are conventions imposed above the core format. Document the convention next to the field. Otherwise two clients can parse the same text successfully and still interpret it differently.

How JSON Travels Through an API

An HTTP API can put JSON in a request body, a response body, or both. The Content-Type field identifies the representation so the recipient can choose a suitable parser. The HTTP semantics specification separates message metadata from the body being transferred. An HTTP success status says something about the request outcome; the response body describes the returned resource or result.

A client should check the response status and expected media type before assuming every body is JSON. Authentication failures, gateway errors, and maintenance pages can return another format. Parse only after confirming that the received body belongs to the expected operation. Then inspect a documented field path rather than assuming all services wrap results in a property called data.

The Scrapeless Scraping API introduction describes actor-selected requests and structured output. That is a concrete use for JSON: an application sends a documented input object and reads the actor-specific result. Different actors can have different fields, so a single generic parser may decode the text while a product-specific mapping still has to interpret it.

Objects, Arrays, and Missing Values

An object answers a question about named properties; an array answers a question about sequence. A list of search results is naturally represented as an array of result objects, with each object holding fields such as a title and a link. The surrounding response object may also carry pagination or metadata. Separating those levels makes it easier to explain which fields describe one result and which describe the whole request.

A missing property is not the same as a property whose value is null. Missing can mean that the producer omitted a field; null explicitly appears in the document. Neither case should automatically be treated as zero or an empty string. Decide how the consuming application handles each case, and test that decision against the actual API contract.

Numbers deserve similar care. JSON supplies a number grammar, but languages differ in how they store very large integers and decimal fractions. Money and identifiers may need a documented string or decimal representation rather than a floating-point assumption. The JavaScript JSON interface shows the familiar parse and serialize operations, while the data model still requires application-level decisions.

Validating and Debugging JSON in Practice

Begin with the raw response rather than a screenshot of what a dashboard displayed. Confirm its status, media type, and complete body. If parsing fails, locate the first syntax error: an unescaped quote, a missing closing bracket, or a trailing comma is often enough. If parsing succeeds but the application still fails, inspect the path and type of the field the application expects.

Write checks against meaning rather than mere presence. A result array can be present and empty; that may be a valid no-results outcome or evidence of an upstream access problem. A URL can be a string and still point to an unrelated page. Keep a small set of known-good and edge-case responses as contract examples, clearly labelled as examples rather than live captures.

When ingesting public web data, preserve a link to the source record and the observation context when the workflow needs auditability. Scrapeless Scraping API is one way to obtain structured results from supported sources. The application that stores those results should still validate the actor-specific schema and decide how to handle fields that vary across targets.

When JSON Is the Right Representation

JSON is a strong fit for exchanging small to moderately sized structured records between web services and clients. It is readable without a specialist viewer, and most languages have mature parsers. That makes it convenient for configuration, API requests, and extracted records that need to pass through several systems. Readability does not mean a human should edit production payloads by hand.

For tabular exports, CSV may be easier for spreadsheets, although it does not naturally represent nested structures. HTML preserves page structure and presentation but usually needs extraction before an application can query business fields reliably. A binary format may reduce size or add a stronger schema for high-volume internal traffic. Choose according to the shape of the data and the systems that consume it.

A useful design question is whether the consumer needs the original page or a selected record. If the consumer needs a product title and availability from a supported actor, structured JSON reduces parsing work. If the consumer needs to inspect the exact markup that produced a result, retain or request a suitable page representation as well. The related Scraper API actor guide illustrates why output envelopes and fields must be read actor by actor.

Conclusion

JSON supplies a precise text grammar for exchanging structured values. It does not supply the business rules that make those values reliable. Define the expected shape, inspect actual API responses, and validate the fields your application uses before treating a parsed document as a trustworthy record.

Turn Structured Web Data Into Usable Records

Explore the documented Scraping API actors and map their returned fields to your application schema.

Sign up today and get $5 in free credit — no credit card required.

Claim Your $5 Credit →

FAQ

Is JSON the same as JavaScript?

JSON is a language-independent data format inspired by JavaScript object notation. JavaScript can parse and serialize JSON, but JSON excludes JavaScript expressions, functions, comments, and undefined values. Treat incoming JSON as data to parse and validate, not as code to execute.

Can a JSON file contain more than one object?

A single JSON text can have an array containing many objects, or one object that contains nested objects. It cannot contain several top-level JSON values simply placed one after another and still be one standard JSON text. A separate line-oriented format is sometimes used for that purpose.

Does valid JSON mean the data is correct?

Valid JSON only means that the text obeys JSON syntax. The contents may be incomplete, stale, misleading, or incompatible with the consumer schema. Check required fields, types, source context, and business rules after parsing.

Why does an API sometimes return HTML instead of JSON?

An API client can receive HTML when it reaches a web page, an access challenge, or an error surface rather than the expected API response. Inspect the HTTP status, final URL, and media type before parsing. A successful network connection alone does not establish that the intended JSON result was delivered.

References