@loaders.gl/loader-utils
Version:
Framework-independent loaders for 3D graphics formats
13 lines (11 loc) • 359 B
text/typescript
import {getFirstCharacters} from '../binary-utils/get-first-characters';
/**
* Minimal JSON parser that throws more meaningful error messages
*/
export function parseJSON(string: string): any {
try {
return JSON.parse(string);
} catch (_) {
throw new Error(`Failed to parse JSON from data starting with "${getFirstCharacters(string)}"`);
}
}