Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
jsoncLoader.ts
Go to the documentation of this file.
1
2
34import type { ParseError } from 'jsonc-parser';
35
65export async function loadJsoncParser() {
66 try {
67 // First try CommonJS require (works inside VSCode)
68 const cjs = require('jsonc-parser');
69 return cjs;
70 } catch (err) {
71 // If that fails (e.g. when running tests under ESM), fallback to dynamic import
72 const esm = await import('jsonc-parser');
73 return esm;
74 }
75}
76
121export async function parseJsonFile(jsonContent: string) {
122 const { parse } = await loadJsoncParser();
123 const errors: ParseError[] = [];
124 const result = parse(jsonContent, errors);
125 if (errors.length > 0) {
126 throw new Error(`JSONC parse errors: ${JSON.stringify(errors)}`);
127 }
128 return result;
129}
import type
function async parseJsonFile(jsonContent:string)
Parses JSONC content with comprehensive error handling and validation.
function async loadJsoncParser()
Loads the jsonc-parser module with automatic fallback between module systems.