Inspect SEC XML as source-native JSON
Select an actual XML document from a filing manifest and inspect its JSON representation while preserving source semantics.
List the documents in a real filing, choose a manifest XML filename, and request source-native JSON. The representation preserves strings and structure rather than claiming normalized financial data.
Requirements: Node.js 22 or later; no extra packages. An API key from your dashboard, stored in the SEC_API_KEY environment variable.
Run the workflow
Save this as workflow.mjs and run node workflow.mjs. The production base URL is used by default. Keep credentials out of source control.
// Node.js 22+. Set SEC_API_KEY before running.
const key = process.env.SEC_API_KEY;
if (!key) throw new Error("Set SEC_API_KEY first");
const base = process.env.SEC_API_BASE_URL || "https://sec-api.dev";
async function request(path) {
const response = await fetch(base + path, {
headers: { Authorization: "Bearer " + key }
});
if (!response.ok) {
throw new Error("HTTP " + response.status + ": " + await response.text());
}
return response.json();
}
const cik = "320193";
const filings = await request("/api/v1/filings?" + new URLSearchParams({cik,form:"4",limit:"1"}));
if (!filings.data.length) throw new Error("No recent Form 4");
const identity = {cik,accession:filings.data[0].accessionNumber};
const manifest = await request("/api/v1/documents?" + new URLSearchParams(identity));
const candidates = manifest.data.filter(row => row.mediaType === "application/xml");
const selected = candidates.find(row => /ownership|form4/i.test(row.name))
|| (candidates.length === 1 ? candidates[0] : null);
if (!selected) throw new Error("Inspect the manifest and choose an XML document explicitly");
const result = await request("/api/v1/filing-xml?" + new URLSearchParams({
...identity,document:selected.name
}));
console.log(JSON.stringify({document:selected.name, rootKeys:Object.keys(result.data),
source:result.meta, data:result.data}, null, 2));Choose an actual XML document
The accession’s manifest is the source of valid filenames. The example first looks for an ownership-style filename, then allows a single unambiguous XML candidate. If several candidates remain, it stops rather than guessing. For other form families, inspect the manifest and choose the appropriate source document explicitly.
Keep the representation boundary visible
The converter removes namespace prefixes, prefixes attribute names with@_, and represents repeated elements as arrays. Numeric-looking values remain strings. This is a useful representation for inspecting a source schema, but it is not a standardized financial statement or an extracted offering dataset. A field’s meaning still comes from the filing’s schema and instructions.
Use a specialized endpoint when it matches the task
The generic response has a900KB size ceiling. For supported ownership and13F workflows, the dedicated parsed endpoints provide bounded row pagination and explicit record types. For larger unsupported XML, use paged document text and a source-aware parser in your own environment. Preserve the document identity and representation metadata so a future consumer knows which transformations occurred.
Sources and further reading
The underlying SEC dataset behavior is documented in the official SEC API reference and SEC technical specifications. Response-field names shown here belong to the sec-api.dev endpoint contract. The scripts print actual results and do not embed fabricated filing or financial data.
All tutorials ←