Response formats
One search resource, six spellings of the answer. Pick with
format=; JSON is the default and the one the others are described
in terms of.
format | Content-Type | Shape |
|---|---|---|
json | application/json | One object, results in an array. |
ndjson | application/x-ndjson | One JSON object per line. The first line is the metadata, tagged "object":"meta". |
xml | application/xml | The same document as XML, rows as <result>. |
csv | text/csv | Semicolon separated, no header line. |
tsv | text/tab-separated-values | As CSV, tab separated. |
txt | text/plain | One url per line. |
jsonl is accepted as another name for ndjson.
The files the results page on the site gives - the URLs, CSV and CSV+snippets buttons - are described in Downloading results.
Which to use
json for anything that fits in memory. ndjson for anything that does not: there is no enclosing array to wait for, the metadata arrives before the rows, and a reader can start work on the first result while the rest is still arriving. csv, tsv and txt for spreadsheets and shell pipelines.
ndjson
{"object":"meta","query":"\"angular.min.js\"","page":1,"per_page":2,"total":70907,"total_pages":35454,"returned":2,"truncated":false,"index_complete":true,"took_ms":2}
{"domain":"imgbox.com","url":"https://imgbox.com/","rank":4187,"ranked":true}
{"domain":"angularjs.org","url":"https://angularjs.org/","rank":12376,"ranked":true}
Choosing the columns
json and xml return every field. The flat formats
default to the familiar ones instead, so a script coming from the old export
urls needs no parser change:
| Request | Output |
|---|---|
format=csv | imgbox.com;4187 |
format=csv&columns=url,rank | https://imgbox.com/;4187 |
format=csv&columns=domain | imgbox.com |
format=txt | https://imgbox.com/ |
format=csv&snippets=1 | imgbox.com;4187;the matching text;the page title |
format=csv&header=1 | a domain;rank line first |
format=csv&delimiter=, | imgbox.com,4187 |
With depth: other than 0 in the query, a row is a page, and in csv and tsv the rows of one website look alike: to see which page it is, ask for url - columns=domain,rank,url.
columns works for every format, so format=json with
columns=domain returns objects with only that field.
Details of the flat formats
- A value is quoted only when it would otherwise break the row - it contains the delimiter, a quote or a newline. Ordinary
domain;rankoutput is bare. - Quotes inside a quoted value are doubled, as CSV expects.
- A value a spreadsheet would run as a formula, such as one starting with
=,+,-or@, gets a leading apostrophe incsvandtsv. A value made only of number characters, such as+49 211 123or-15, stays as it is. - Snippets, being a list, are joined with
...into one cell. - An unranked site has an empty rank cell, which is how
nullspells itself here. - The totals cannot fit in a row, so they are in the
X-Total-Results,X-Returned-Results,X-TruncatedandX-Index-Completeheaders instead, andquery_noteinX-Query-Note. Those are sent whatever the format,X-Query-Noteonly when there is a note.
The flat formats are the new API's own; only the old urls promise the old exports byte for byte.
Formats and errors
csv, tsv and txt fit search results only;
anywhere else, /v1/account included, they are
400 format_not_available - except csv on
/v1/clusters/{id}/extract (comma separated by default;
delimiter changes it - see Clusters)
and txt on /v1/clusters/{id}, one domain per line. On
cluster endpoints a refused format spends and changes nothing. Errors come back as
JSON, or as XML if asked for - see Errors.