Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonrepair

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonrepair - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

7

CHANGELOG.md
# Changelog
## 2021-06-09, version 2.2.1
- Improved handling of trailing commas.
- Improved handling of newline delimited JSON containing commas.
- Improved handling of repairing objects/arrays with missing closing bracket.
## 2021-04-01, version 2.2.0

@@ -4,0 +11,0 @@

36

lib/cjs/jsonrepair.js

@@ -106,6 +106,8 @@ "use strict";

processNextToken();
var isRootLevelObject = tokenType === DELIMITER && token === '{'; // parse everything
var rootLevelTokenType = tokenType; // parse everything
parseObject();
parseObject(); // ignore trailing comma
skipComma();
if (token === '') {

@@ -116,3 +118,3 @@ // reached the end of the document properly

if (isRootLevelObject && tokenIsStartOfValue()) {
if (rootLevelTokenType === tokenType && tokenIsStartOfValue()) {
// start of a new value after end of the root level object: looks like

@@ -122,3 +124,3 @@ // newline delimited JSON -> turn into a root level array

while (tokenIsStartOfValue()) {
while (rootLevelTokenType === tokenType && tokenIsStartOfValue()) {
output = (0, _stringUtils.insertBeforeLastWhitespace)(output, ',');

@@ -128,3 +130,5 @@ stashedOutput += output;

parseObject();
parseObject(); // ignore trailing comma
skipComma();
} // wrap the output in an array

@@ -205,2 +209,10 @@

}
}
function skipComma() {
if (token === ',') {
token = '';
tokenType = UNKNOWN;
processNextToken();
}
} // check for delimiters like ':', '{', ']'

@@ -493,2 +505,9 @@

}
if (token === '') {
// end of json reached, but missing }
// Strip the missing comma (the closing bracket will be added later)
output = (0, _stringUtils.stripLastOccurrence)(output, ',');
break;
}
} else {

@@ -544,2 +563,9 @@ if (tokenIsStartOfKey()) {

}
if (token === '') {
// end of json reached, but missing ]
// Strip the missing comma (the closing bracket will be added later)
output = (0, _stringUtils.stripLastOccurrence)(output, ',');
break;
}
} else {

@@ -546,0 +572,0 @@ if (tokenIsStartOfValue()) {

@@ -95,6 +95,8 @@ import JsonRepairError from './JsonRepairError.js';

processNextToken();
var isRootLevelObject = tokenType === DELIMITER && token === '{'; // parse everything
var rootLevelTokenType = tokenType; // parse everything
parseObject();
parseObject(); // ignore trailing comma
skipComma();
if (token === '') {

@@ -105,3 +107,3 @@ // reached the end of the document properly

if (isRootLevelObject && tokenIsStartOfValue()) {
if (rootLevelTokenType === tokenType && tokenIsStartOfValue()) {
// start of a new value after end of the root level object: looks like

@@ -111,3 +113,3 @@ // newline delimited JSON -> turn into a root level array

while (tokenIsStartOfValue()) {
while (rootLevelTokenType === tokenType && tokenIsStartOfValue()) {
output = insertBeforeLastWhitespace(output, ',');

@@ -117,3 +119,5 @@ stashedOutput += output;

parseObject();
parseObject(); // ignore trailing comma
skipComma();
} // wrap the output in an array

@@ -193,2 +197,10 @@

}
}
function skipComma() {
if (token === ',') {
token = '';
tokenType = UNKNOWN;
processNextToken();
}
} // check for delimiters like ':', '{', ']'

@@ -481,2 +493,9 @@

}
if (token === '') {
// end of json reached, but missing }
// Strip the missing comma (the closing bracket will be added later)
output = stripLastOccurrence(output, ',');
break;
}
} else {

@@ -532,2 +551,9 @@ if (tokenIsStartOfKey()) {

}
if (token === '') {
// end of json reached, but missing ]
// Strip the missing comma (the closing bracket will be added later)
output = stripLastOccurrence(output, ',');
break;
}
} else {

@@ -534,0 +560,0 @@ if (tokenIsStartOfValue()) {

@@ -287,6 +287,8 @@ (function (global, factory) {

processNextToken();
var isRootLevelObject = tokenType === DELIMITER && token === '{'; // parse everything
var rootLevelTokenType = tokenType; // parse everything
parseObject();
parseObject(); // ignore trailing comma
skipComma();
if (token === '') {

@@ -297,3 +299,3 @@ // reached the end of the document properly

if (isRootLevelObject && tokenIsStartOfValue()) {
if (rootLevelTokenType === tokenType && tokenIsStartOfValue()) {
// start of a new value after end of the root level object: looks like

@@ -303,3 +305,3 @@ // newline delimited JSON -> turn into a root level array

while (tokenIsStartOfValue()) {
while (rootLevelTokenType === tokenType && tokenIsStartOfValue()) {
output = insertBeforeLastWhitespace(output, ',');

@@ -309,3 +311,5 @@ stashedOutput += output;

parseObject();
parseObject(); // ignore trailing comma
skipComma();
} // wrap the output in an array

@@ -385,2 +389,10 @@

}
}
function skipComma() {
if (token === ',') {
token = '';
tokenType = UNKNOWN;
processNextToken();
}
} // check for delimiters like ':', '{', ']'

@@ -672,2 +684,9 @@

}
if (token === '') {
// end of json reached, but missing }
// Strip the missing comma (the closing bracket will be added later)
output = stripLastOccurrence(output, ',');
break;
}
} else {

@@ -723,2 +742,9 @@ if (tokenIsStartOfKey()) {

}
if (token === '') {
// end of json reached, but missing ]
// Strip the missing comma (the closing bracket will be added later)
output = stripLastOccurrence(output, ',');
break;
}
} else {

@@ -725,0 +751,0 @@ if (tokenIsStartOfValue()) {

2

lib/umd/jsonrepair.min.js

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).jsonrepair=n()}(this,function(){"use strict";function f(e,n){if(!(this instanceof f))throw new SyntaxError("Constructor must be called with the new operator");this.message=e+" (char "+n+")",this.char=n,this.stack=(new Error).stack}(f.prototype=new Error).constructor=Error;var o={"'":!0,"‘":!0,"’":!0,"`":!0,"´":!0},u={'"':!0,"“":!0,"”":!0};function c(e){return n.test(e)}var n=/^[a-zA-Z_]$/;var s=/^[0-9a-fA-F]$/;function a(e){return t.test(e)}var t=/^[0-9]$/;function l(e){return" "===e||"\t"===e||"\n"===e||"\r"===e}function h(e){return" "===e||" "<=e&&e<=" "||" "===e||" "===e||" "===e}function d(e){return!0===o[e]}function w(e){return!0===u[e]}function g(e){return!0===o[e]?"'":!0===u[e]?'"':e}function e(e,n){n=e.lastIndexOf(n);return-1!==n?e.substring(0,n)+e.substring(n+1):e}function r(e,n){var t=e.length;if(!l(e[t-1]))return e+n;for(;l(e[t-1]);)t--;return e.substring(0,t)+n+e.substring(t)}var i=0,b=1,p=2,v=3,x=4,m=5,y=6,k={"":!0,"{":!0,"}":!0,"[":!0,"]":!0,":":!0,",":!0,"(":!0,")":!0,";":!0,"+":!0},I={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},E={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},A={null:"null",true:"true",false:"false"},j={None:"null",True:"true",False:"false"},$="",O="",T=0,C="",F="",S=y;function U(){T++,C=$.charAt(T)}function z(){U(),"\\"===C&&U()}function N(){return S===i&&("["===F||"{"===F)||S===p||S===b||S===v}function V(){O+=F,S=y,F="",k[C]?(S=i,F=C,U()):function(){if(a(C)||"-"===C){if(S=b,"-"===C){if(F+=C,U(),!a(C))throw new f("Invalid number, digit expected",T)}else"0"===C&&(F+=C,U());for(;a(C);)F+=C,U();if("."===C){if(F+=C,U(),!a(C))throw new f("Invalid number, digit expected",T);for(;a(C);)F+=C,U()}if("e"===C||"E"===C){if(F+=C,U(),"+"!==C&&"-"!==C||(F+=C,U()),!a(C))throw new f("Invalid number, digit expected",T);for(;a(C);)F+=C,U()}}else"\\"===C&&'"'===$.charAt(T+1)?(U(),Z(z)):Z(U)}(),S===x&&(F=function(e){for(var n="",t=0;t<e.length;t++){var r=e[t];n+=h(r)?" ":r}return n}(F),V()),S===m&&(S=y,F="",V())}function Z(e){if(!0===o[n=C]||!0===u[n]){var n=g(C),t=d(C)?d:w;for(F+='"',S=p,e();""!==C&&!t(C);)if("\\"===C)if(e(),void 0!==I[C])F+="\\"+C,e();else if("u"===C){F+="\\u",e();for(var r=0;r<4;r++){if(i=C,!s.test(i))throw new f("Invalid unicode character",T-F.length);F+=C,e()}}else{if("'"!==C)throw new f('Invalid escape character "\\'+C+'"',T);F+="'",e()}else E[C]?F+=E[C]:F+='"'===C?'\\"':C,e();if(g(C)!==n)throw new f("End of string expected",T-F.length);return F+='"',void e()}var i,n;!function(){if(c(C))for(S=v;c(C)||a(C)||"$"===C;)F+=C,U();else!function(){if(l(C)||h(C))for(S=x;l(C)||h(C);)F+=C,U();else!function(){if("/"!==C||"*"!==$[T+1])if("/"!==C||"/"!==$[T+1])!function(){S=y;for(;""!==C;)F+=C,U();throw new f('Syntax error in part "'+F+'"',T-F.length)}();else for(S=m;""!==C&&"\n"!==C;)F+=C,U();else{for(S=m;""!==C&&("*"!==C||"*"===C&&"/"!==$[T+1]);)F+=C,U();"*"===C&&"/"===$[T+1]&&(F+=C,U(),F+=C,U())}}()}()}()}function _(){if(S!==i||"{"!==F)!function(){if(S!==i||"["!==F)!function(){if(S!==p)(S!==b?function(){if(S!==v)!function(){throw new f(""===F?"Unexpected end of json string":"Value expected",T-F.length)}();else if(A[F])V();else{if(j[F])return F=j[F],V();var e=F,n=O.length;if(F="",V(),S===i&&"("===F)return F="",V(),_(),S===i&&")"===F&&(F="",V(),S===i&&";"===F&&(F="",V()));for(O=function(e,n,t){return e.substring(0,t)+n+e.substring(t)}(O,'"'.concat(e),n);S===v||S===b;)V();O+='"'}}:V)();else for(V();S===i&&"+"===F;){var e;F="",V(),S===p&&(e=O.lastIndexOf('"'),O=O.substring(0,e)+F.substring(1),F="",V())}}();else if(V(),S!==i||"]"!==F){for(;;)if(_(),S===i&&","===F){if(V(),S===i&&"]"===F){O=e(O,",");break}}else{if(!N())break;O=r(O,",")}S===i&&"]"===F?V():O=r(O,"]")}else V()}();else if(V(),S!==i||"}"!==F){for(;;){if(S!==v&&S!==b||(S=p,F='"'.concat(F,'"')),S!==p)throw new f("Object key expected",T-F.length);if(V(),S===i&&":"===F)V();else{if(!N())throw new f("Colon expected",T-F.length);O=r(O,":")}if(_(),S===i&&","===F){if(V(),S===i&&"}"===F){O=e(O,",");break}}else{if(S!==p&&S!==b&&S!==v)break;O=r(O,",")}}S===i&&"}"===F?V():O=r(O,"}")}else V()}return function(e){if(O="",T=0,C=($=e).charAt(0),F="",S=y,V(),e=S===i&&"{"===F,_(),""===F)return O;if(e&&N()){for(var n="";N();)n+=O=r(O,","),O="",_();return"[\n".concat(n).concat(O,"\n]")}throw new f("Unexpected characters",T-F.length)}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).jsonrepair=n()}(this,function(){"use strict";function f(e,n){if(!(this instanceof f))throw new SyntaxError("Constructor must be called with the new operator");this.message=e+" (char "+n+")",this.char=n,this.stack=(new Error).stack}(f.prototype=new Error).constructor=Error;var o={"'":!0,"‘":!0,"’":!0,"`":!0,"´":!0},u={'"':!0,"“":!0,"”":!0};function c(e){return n.test(e)}var n=/^[a-zA-Z_]$/;var s=/^[0-9a-fA-F]$/;function a(e){return t.test(e)}var t=/^[0-9]$/;function l(e){return" "===e||"\t"===e||"\n"===e||"\r"===e}function h(e){return" "===e||" "<=e&&e<=" "||" "===e||" "===e||" "===e}function d(e){return!0===o[e]}function w(e){return!0===u[e]}function b(e){return!0===o[e]?"'":!0===u[e]?'"':e}function e(e,n){n=e.lastIndexOf(n);return-1!==n?e.substring(0,n)+e.substring(n+1):e}function r(e,n){var t=e.length;if(!l(e[t-1]))return e+n;for(;l(e[t-1]);)t--;return e.substring(0,t)+n+e.substring(t)}var i=0,g=1,v=2,p=3,x=4,k=5,m=6,y={"":!0,"{":!0,"}":!0,"[":!0,"]":!0,":":!0,",":!0,"(":!0,")":!0,";":!0,"+":!0},I={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},E={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},A={null:"null",true:"true",false:"false"},j={None:"null",True:"true",False:"false"},$="",O="",T=0,C="",F="",S=m;function U(){T++,C=$.charAt(T)}function z(){U(),"\\"===C&&U()}function N(){return S===i&&("["===F||"{"===F)||S===v||S===g||S===p}function V(){O+=F,S=m,F="",y[C]?(S=i,F=C,U()):function(){if(a(C)||"-"===C){if(S=g,"-"===C){if(F+=C,U(),!a(C))throw new f("Invalid number, digit expected",T)}else"0"===C&&(F+=C,U());for(;a(C);)F+=C,U();if("."===C){if(F+=C,U(),!a(C))throw new f("Invalid number, digit expected",T);for(;a(C);)F+=C,U()}if("e"===C||"E"===C){if(F+=C,U(),"+"!==C&&"-"!==C||(F+=C,U()),!a(C))throw new f("Invalid number, digit expected",T);for(;a(C);)F+=C,U()}}else"\\"===C&&'"'===$.charAt(T+1)?(U(),_(z)):_(U)}(),S===x&&(F=function(e){for(var n="",t=0;t<e.length;t++){var r=e[t];n+=h(r)?" ":r}return n}(F),V()),S===k&&(S=m,F="",V())}function Z(){","===F&&(F="",S=m,V())}function _(e){if(!0===o[n=C]||!0===u[n]){var n=b(C),t=d(C)?d:w;for(F+='"',S=v,e();""!==C&&!t(C);)if("\\"===C)if(e(),void 0!==I[C])F+="\\"+C,e();else if("u"===C){F+="\\u",e();for(var r=0;r<4;r++){if(i=C,!s.test(i))throw new f("Invalid unicode character",T-F.length);F+=C,e()}}else{if("'"!==C)throw new f('Invalid escape character "\\'+C+'"',T);F+="'",e()}else E[C]?F+=E[C]:F+='"'===C?'\\"':C,e();if(b(C)!==n)throw new f("End of string expected",T-F.length);return F+='"',void e()}var i,n;!function(){if(c(C))for(S=p;c(C)||a(C)||"$"===C;)F+=C,U();else!function(){if(l(C)||h(C))for(S=x;l(C)||h(C);)F+=C,U();else!function(){if("/"!==C||"*"!==$[T+1])if("/"!==C||"/"!==$[T+1])!function(){S=m;for(;""!==C;)F+=C,U();throw new f('Syntax error in part "'+F+'"',T-F.length)}();else for(S=k;""!==C&&"\n"!==C;)F+=C,U();else{for(S=k;""!==C&&("*"!==C||"*"===C&&"/"!==$[T+1]);)F+=C,U();"*"===C&&"/"===$[T+1]&&(F+=C,U(),F+=C,U())}}()}()}()}function q(){if(S!==i||"{"!==F)!function(){if(S!==i||"["!==F)!function(){if(S!==v)(S!==g?function(){if(S!==p)!function(){throw new f(""===F?"Unexpected end of json string":"Value expected",T-F.length)}();else if(A[F])V();else{if(j[F])return F=j[F],V();var e=F,n=O.length;if(F="",V(),S===i&&"("===F)return F="",V(),q(),S===i&&")"===F&&(F="",V(),S===i&&";"===F&&(F="",V()));for(O=function(e,n,t){return e.substring(0,t)+n+e.substring(t)}(O,'"'.concat(e),n);S===p||S===g;)V();O+='"'}}:V)();else for(V();S===i&&"+"===F;){var e;F="",V(),S===v&&(e=O.lastIndexOf('"'),O=O.substring(0,e)+F.substring(1),F="",V())}}();else if(V(),S!==i||"]"!==F){for(;;)if(q(),S===i&&","===F){if(V(),S===i&&"]"===F){O=e(O,",");break}if(""===F){O=e(O,",");break}}else{if(!N())break;O=r(O,",")}S===i&&"]"===F?V():O=r(O,"]")}else V()}();else if(V(),S!==i||"}"!==F){for(;;){if(S!==p&&S!==g||(S=v,F='"'.concat(F,'"')),S!==v)throw new f("Object key expected",T-F.length);if(V(),S===i&&":"===F)V();else{if(!N())throw new f("Colon expected",T-F.length);O=r(O,":")}if(q(),S===i&&","===F){if(V(),S===i&&"}"===F){O=e(O,",");break}if(""===F){O=e(O,",");break}}else{if(S!==v&&S!==g&&S!==p)break;O=r(O,",")}}S===i&&"}"===F?V():O=r(O,"}")}else V()}return function(e){O="",T=0,C=($=e).charAt(0),F="",S=m,V();var n=S;if(q(),Z(),""===F)return O;if(n===S&&N()){for(var t="";n===S&&N();)t+=O=r(O,","),O="",q(),Z();return"[\n".concat(t).concat(O,"\n]")}throw new f("Unexpected characters",T-F.length)}});
{
"name": "jsonrepair",
"version": "2.2.0",
"version": "2.2.1",
"description": "Repair broken JSON documents",

@@ -47,16 +47,16 @@ "repository": {

"devDependencies": {
"@babel/cli": "7.13.14",
"@babel/core": "7.13.14",
"@babel/preset-env": "7.13.12",
"@babel/cli": "7.14.3",
"@babel/core": "7.14.3",
"@babel/preset-env": "7.14.4",
"cpy-cli": "3.1.1",
"del-cli": "3.0.1",
"eslint": "7.23.0",
"eslint-config-standard": "16.0.2",
"eslint-plugin-import": "2.22.1",
"eslint": "7.28.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.3.1",
"mocha": "8.3.2",
"rollup": "2.44.0",
"uglify-js": "3.13.3"
"eslint-plugin-promise": "5.1.0",
"mocha": "9.0.0",
"rollup": "2.51.1",
"uglify-js": "3.13.9"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc