--- title: parse description: Decode already-available data with a loader. hide_title: true page_style: designed --- import {DocPageHeader} from '@site/src/components/docs/doc-page-header'; import {DocOrientation, ReferenceBoundary} from '@site/src/components/docs/designed-doc'; This function parses data atomically, meaning that the complete result is returned in one operation. It is intended for already available data such as `ArrayBuffer` and `string` objects. In contrast to `load()`, `parse()` does not interpret strings as URLs. It does read data from `Response` objects, which can involve consuming a response body stream. :::caution When calling a sub-loader from inside a loader, do not use this public function. Use the `parseFromContext` counterparts in `@loaders.gl/core/loader-utils`. ::: ## Usage The return value from `fetch` or `fetchFile` is a `Promise` that resolves to the fetch `Response` object and can be passed directly to the non-sync parser functions: ```typescript import {fetchFile, parse} from '@loaders.gl/core'; import {OBJLoader} from '@loaders.gl/scene/obj'; const data = await parse(fetchFile(url), OBJLoader); // Application code here ... ``` For worker-enabled loaders, atomic `parse()` uses the worker by default when the runtime supports it. Use `core.worker: false` to keep the work on the calling thread, or opt into loader-provided cost estimates with `core.worker: 'auto'` and `core.workerThreshold` when small inputs should avoid worker startup and transfer overhead. See [Using worker loaders](/docs/developer-guide/using-worker-loaders) for worker availability, transfer ownership, and fallback behavior. Some loaders also support batched (streaming) parsing: ```typescript import {fetchFile, parseInBatches} from '@loaders.gl/core'; import {CSVLoader} from '@loaders.gl/tables/csv'; const batchIterator = await parseInBatches(fetchFile(url), CSVLoader); for await (const batch of batchIterator) { console.log(batch.length); } ``` Errors ```typescript try { const response = await fetch(url); // fetch can throw in case of network errors const data = await parse(response); // parse will throw if server reports an error } catch (error) { console.log(error); } ``` ## Functions ### parse(data, loaders?, options?) Parses data asynchronously using the provided loader or loaders, or using the pre-registered loaders (see [`registerLoaders`](./register-loaders)). | Input | Description | | --- | --- | | `Response` | A response returned by `fetch()` or `fetchFile()`; its body can be consumed as a stream. | | `ArrayBuffer`, `Uint8Array`, or `string` | Already loaded binary or textual data. Strings are treated as data, not URLs. | | `File` or `Blob` | Browser file data. | | `Iterator` or `AsyncIterator` | Binary or textual chunks for loaders that support streaming input. | | `ReadableStream` | A DOM or Node stream. | | `Promise` | A promise resolving to any supported input type. | `loaders` can be a single loader, an array of candidates, or omitted when loaders have been registered. `options` uses [`LoaderOptions`](./loader-options), including an optional `url` hint for loader selection. The return value depends on the selected loader's category data. Note that additional data types can be converted to `Response` objects and used with `parse`, e.g. with `new Response(new FormData(...))`. See browser documentation for the `Response` class for more details.