diff --git a/lib/Serializer.js b/lib/Serializer.js index 4fb5123c4..a4befaed6 100644 --- a/lib/Serializer.js +++ b/lib/Serializer.js @@ -34,6 +34,7 @@ const debug = require('debug')('opensearch'); const sjson = require('secure-json-parse'); const { SerializationError, DeserializationError } = require('./errors'); const kJsonOptions = Symbol('secure json parse options'); +const JSON11 = require('json11'); /* In JavaScript, a `Number` is a 64-bit floating-point value which can store 16 digits. However, the * serializer and deserializer will need to cater to numeric values generated by other languages which @@ -265,7 +266,12 @@ class Serializer { json = JSON.stringify(object, shouldHandleLongNumerals ? checkForBigInts : null); if (shouldHandleLongNumerals && !numeralsAreNumbers) { - const temp = this._stringifyWithBigInt(object, json); + // With `withBigInt: false`, valid JSON is produced while maintaining accuracy + const temp = JSON11.stringify(object, { + withBigInt: false, + quote: '"', + quoteNames: true, + }); if (temp) json = temp; } } catch (err) { @@ -299,7 +305,7 @@ class Serializer { ); if (shouldHandleLongNumerals && !numeralsAreNumbers) { - const temp = this._parseWithBigInt(json); + const temp = JSON11.parse(json, null, { withLongNumerals: true }); if (temp) { object = temp; } diff --git a/package.json b/package.json index 2f769ae0b..a0cb2bf97 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "xmlbuilder2": "^3.0.2" }, "dependencies": { + "json11": "^1.0.2", "aws4": "^1.11.0", "debug": "^4.3.1", "hpagent": "^1.2.0", diff --git a/yarn.lock b/yarn.lock index eb92932d7..2d995ca0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2224,6 +2224,11 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE= +json11@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/json11/-/json11-1.0.2.tgz#98e6a3a01d3ed03d40c3ecc7e945767d23287b6f" + integrity sha512-XnGnLo/fE2gsyK+VSPZCOB0IQlJfQaDVIPd4A+KvK+1inMQbm1eEimu/1JzTZgZ0YO/n2WJcdJGDgPHtiQynjw== + json5@^2.1.2: version "2.2.3" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"