parseJSON = (json) => {
  try {
    const parsedJson = Hjson.parse(json);
    if (typeof parsedJson === "object") {
      return parsedJson;
    } else {
      throw new IncorrectJsonFormatError(
        "PR diff is not a valid theme JSON object.",
      );
    }
  } catch (error) {
    // Resolve eslint no-unused-vars
    error;

    // Remove trailing commas (if any).
    let parsedJson = json.replace(/(,\s*})/g, "}");

    // Remove JS comments (if any).
    parsedJson = parsedJson.replace(/\/\/[A-z\s]*\s/g, "");

    // Fix incorrect open bracket (if any).
    const splitJson = parsedJson
      .split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
      .filter((x) => typeof x !== "string" || !!x.trim()); // Split json into array of strings and objects.
    if (splitJson[0].replace(/\s+/g, "") === "},") {
      splitJson[0] = "},";
      if (/\s*}\s*,?\s*$/.test(splitJson[1])) {
        splitJson.shift();
      } else {
        splitJson.push(splitJson.shift());
      }
      parsedJson = splitJson.join("");
    }

    // Try to parse the fixed json.
    try {
      return Hjson.parse(parsedJson);
    } catch (error) {
      throw new IncorrectJsonFormatError(
        `Theme JSON file could not be parsed: ${error.message}`,
      );
    }
  }
}
Retrieve javascript object from json string.

@description Wraps the Hjson parse function to fix several known json syntax errors.

@param {string} json The json to parse.
@returns {Object} Object parsed from the json.