import destr from "destr";
import traverse from "traverse";

//#region src/utils/json-parser.ts
/**
* Turn any string value that is valid JSON into an object/array (in place).
* Useful for parsing MCP tool results and other string data that may contain embedded JSON.
*/
function parseEmbeddedJson(data) {
	if (data === null || data === void 0 || typeof data !== "object") return data;
	return traverse(data).map(function(x) {
		if (typeof x === "string") {
			const v = destr(x);
			if (v !== x && (Array.isArray(v) || v && typeof v === "object")) this.update(v);
		}
	});
}

//#endregion
export { parseEmbeddedJson };