fixJson.ts 413 B

123456789101112
  1. import {completeJson} from './completeJson';
  2. import {evaluateJson} from './evaluateJson';
  3. /**
  4. * Takes an incomplete JSON string, and returns a hopefully valid JSON string.
  5. * Note that this _can_ fail, so you should check the return value is valid JSON.
  6. */
  7. export function fixJson(incompleteJson: string): string {
  8. const stack = evaluateJson(incompleteJson);
  9. return completeJson(incompleteJson, stack);
  10. }