MCPcopy Create free account
hub / github.com/5e-bits/5e-database / parseJsonArrayContent

Function parseJsonArrayContent

scripts/update/processor.ts:26–45  ·  view source on GitHub ↗

* Parses a string containing JSON array content. * Handles JSON parsing errors and validates that the result is an array. * @param content The raw string content to parse. * @param sourceDescription A description of the content's source (e.g., filepath) for logging. * @returns The parsed data ar

(content: string, sourceDescription: string)

Source from the content-addressed store, hash-verified

24 * @returns The parsed data array, or an empty array if parsing fails or it's not an array.
25 */
26function parseJsonArrayContent(content: string, sourceDescription: string): any[] {
27 if (!content || !content.trim()) {
28 console.warn(`Content from ${sourceDescription} is empty or whitespace.`);
29 return [];
30 }
31 try {
32 const data = JSON.parse(content);
33 if (Array.isArray(data)) {
34 return data;
35 }
36 console.warn(`Data from ${sourceDescription} is not a JSON array. Treating as empty.`);
37 } catch (err) {
38 if (err instanceof SyntaxError) {
39 console.error(`Error parsing JSON from ${sourceDescription}: ${err.message}.`);
40 } else {
41 console.error(`Unexpected error parsing JSON from ${sourceDescription}:`, err);
42 }
43 }
44 return [];
45}
46
47/**
48 * Reads and parses JSON content from a file path.

Callers 4

readFileContentFunction · 0.85
_handleFileModifiedFunction · 0.85
_handleFileRenamedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected