blob: c6f6c77487741a365d2b8c8b668d293d0e75a384 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001'use strict';
2
3/**
4 * Converts a JSON string to object
5 * @param jsonString
6 * @param source
7 */
8const jsonStringToObject = (jsonString, source = {} ) => {
9 const s = jsonString.replace(/'/g, '"');
10 try {
11 return Object.assign(source, JSON.parse(s));
12 }
13 catch (e) {
14 throw new Error(`Failed to parse json string: ${s}. Error: ${e.message}`);
15 }
16};
17
18export { jsonStringToObject };