@proofkit/fmodata
Version:
FileMaker OData API client
28 lines (27 loc) • 803 B
JavaScript
import { ResponseParseError } from "../errors.js";
function sanitizeFileMakerJson(text) {
let result = text.replace(/:\s*\?(?=\s*[,}\]])/g, ": null");
result = result.replace(new RegExp("(?<=[[,])\\s*\\?(?=\\s*[,\\]])", "g"), " null");
return result;
}
async function safeJsonParse(response) {
const text = await response.text();
const sanitized = sanitizeFileMakerJson(text);
try {
return JSON.parse(sanitized);
} catch (err) {
throw new ResponseParseError(
response.url,
`Failed to parse response as JSON: ${err instanceof Error ? err.message : "Unknown error"}`,
{
rawText: sanitized,
cause: err instanceof Error ? err : void 0
}
);
}
}
export {
safeJsonParse,
sanitizeFileMakerJson
};
//# sourceMappingURL=sanitize-json.js.map