Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | /** |
| 4 | * Converts a JSON string to object |
| 5 | * @param jsonString |
| 6 | * @param source |
| 7 | */ |
| 8 | |
| 9 | Object.defineProperty(exports, "__esModule", { |
| 10 | value: true |
| 11 | }); |
| 12 | exports.jsonStringToObject = undefined; |
| 13 | |
| 14 | var _assign = require('babel-runtime/core-js/object/assign'); |
| 15 | |
| 16 | var _assign2 = _interopRequireDefault(_assign); |
| 17 | |
| 18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 19 | |
| 20 | var 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 | |
| 31 | exports.jsonStringToObject = jsonStringToObject; |