blob: 50be00615ea17a24da99065af4542f9c4ea08698 [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 */
8
9Object.defineProperty(exports, "__esModule", {
10 value: true
11});
12exports.jsonStringToObject = undefined;
13
14var _assign = require('babel-runtime/core-js/object/assign');
15
16var _assign2 = _interopRequireDefault(_assign);
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20var jsonStringToObject = function jsonStringToObject(jsonString) {
21 var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
22
23 var s = jsonString.replace(/'/g, '"');
24 try {
25 return (0, _assign2.default)(source, JSON.parse(s));
26 } catch (e) {
27 throw new Error('Failed to parse json string: ' + s + '. Error: ' + e.message);
28 }
29};
30
31exports.jsonStringToObject = jsonStringToObject;