jsonrepair
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -190,4 +190,5 @@ "use strict"; | ||
const processedColon = parseCharacter(_stringUtils.codeColon); | ||
const truncatedText = i >= text.length; | ||
if (!processedColon) { | ||
if ((0, _stringUtils.isStartOfValue)(text[i])) { | ||
if ((0, _stringUtils.isStartOfValue)(text[i]) || truncatedText) { | ||
// repair missing colon | ||
@@ -201,3 +202,3 @@ output = (0, _stringUtils.insertBeforeLastWhitespace)(output, ':'); | ||
if (!processedValue) { | ||
if (processedColon) { | ||
if (processedColon || truncatedText) { | ||
// repair missing object value | ||
@@ -204,0 +205,0 @@ output += 'null'; |
@@ -184,4 +184,5 @@ import { JSONRepairError } from './JSONRepairError.js'; | ||
const processedColon = parseCharacter(codeColon); | ||
const truncatedText = i >= text.length; | ||
if (!processedColon) { | ||
if (isStartOfValue(text[i])) { | ||
if (isStartOfValue(text[i]) || truncatedText) { | ||
// repair missing colon | ||
@@ -195,3 +196,3 @@ output = insertBeforeLastWhitespace(output, ':'); | ||
if (!processedValue) { | ||
if (processedColon) { | ||
if (processedColon || truncatedText) { | ||
// repair missing object value | ||
@@ -198,0 +199,0 @@ output += 'null'; |
@@ -357,4 +357,5 @@ (function (global, factory) { | ||
const processedColon = parseCharacter(codeColon); | ||
const truncatedText = i >= text.length; | ||
if (!processedColon) { | ||
if (isStartOfValue(text[i])) { | ||
if (isStartOfValue(text[i]) || truncatedText) { | ||
// repair missing colon | ||
@@ -368,3 +369,3 @@ output = insertBeforeLastWhitespace(output, ':'); | ||
if (!processedValue) { | ||
if (processedColon) { | ||
if (processedColon || truncatedText) { | ||
// repair missing object value | ||
@@ -371,0 +372,0 @@ output += 'null'; |
@@ -1,3 +0,3 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONRepair={})}(this,function(t){"use strict";class v extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const a=125,e=32,b=10,p=9,w=13,x=8,y=12,$=34,r=39,n=48,o=57,c=65,i=97,f=70,u=102,h=160,O=8192,N=8202,J=8239,S=8287,j=12288,d=8220,l=8221,s=8216,A=8217,C=96,g=180;function I(t){return t>=n&&t<=o||t>=c&&t<=f||t>=i&&t<=u}function k(t){return t>=n&&t<=o}function m(t){return G.test(t)||t&&R(t.charCodeAt(0))}const G=/^[,:[\]{}()\n+]$/;function T(t){return H.test(t)||t&&R(t.charCodeAt(0))}const H=/^[[{\w-]$/;function E(t){return t===e||t===b||t===p||t===w}function R(t){return U(t)||q(t)}function U(t){return t===$||t===d||t===l}function F(t){return t===$}function q(t){return t===r||t===s||t===A||t===C||t===g}function z(t){return t===r}function B(t,e,r){r=2<arguments.length&&void 0!==r&&r,e=t.lastIndexOf(e);return-1!==e?t.substring(0,e)+(r?"":t.substring(e+1)):t}function D(t,e){let r=t.length;if(!E(t.charCodeAt(r-1)))return t+e;for(;E(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const K={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},L={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=v,t.jsonrepair=function(d){let l=0,s="";if(!o())throw new v("Unexpected end of json string",d.length);var t=c(44);if(t&&A(),T(d[l])&&/[,\n][ \t\r]*$/.test(s)){t||(s=D(s,","));{let t=!0,e=!0;for(;e;)t?t=!1:c(44)||(s=D(s,",")),e=o();e||(s=B(s,","));s=`[ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONRepair={})}(this,function(t){"use strict";class v extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const a=125,e=32,b=10,p=9,w=13,x=8,y=12,$=34,r=39,n=48,o=57,c=65,i=97,f=70,u=102,h=160,O=8192,N=8202,J=8239,S=8287,j=12288,d=8220,l=8221,s=8216,A=8217,C=96,g=180;function I(t){return t>=n&&t<=o||t>=c&&t<=f||t>=i&&t<=u}function k(t){return t>=n&&t<=o}function m(t){return G.test(t)||t&&R(t.charCodeAt(0))}const G=/^[,:[\]{}()\n+]$/;function T(t){return H.test(t)||t&&R(t.charCodeAt(0))}const H=/^[[{\w-]$/;function E(t){return t===e||t===b||t===p||t===w}function R(t){return U(t)||q(t)}function U(t){return t===$||t===d||t===l}function F(t){return t===$}function q(t){return t===r||t===s||t===A||t===C||t===g}function z(t){return t===r}function B(t,e,r){r=2<arguments.length&&void 0!==r&&r,e=t.lastIndexOf(e);return-1!==e?t.substring(0,e)+(r?"":t.substring(e+1)):t}function D(t,e){let r=t.length;if(!E(t.charCodeAt(r-1)))return t+e;for(;E(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const K={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},L={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=v,t.jsonrepair=function(d){let l=0,s="";if(!c())throw new v("Unexpected end of json string",d.length);var t=i(44);if(t&&A(),T(d[l])&&/[,\n][ \t\r]*$/.test(s)){t||(s=D(s,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(s=D(s,",")),e=c();e||(s=B(s,","));s=`[ | ||
${s} | ||
]`}}else t&&(s=B(s,","));for(;d.charCodeAt(l)===a||93===d.charCodeAt(l);)l++,A();if(l>=d.length)return s;throw new v("Unexpected character "+JSON.stringify(d[l]),l);function o(){A();var t=function(){if(123!==d.charCodeAt(l))return!1;{s+="{",l++,A();let e=!0;for(;l<d.length&&d.charCodeAt(l)!==a;){let t;if(e?(t=!0,e=!1):((t=c(44))||(s=D(s,",")),A()),!(g()||i())){d.charCodeAt(l)===a||123===d.charCodeAt(l)||93===d.charCodeAt(l)||91===d.charCodeAt(l)||void 0===d[l]?s=B(s,","):function(){throw new v("Object key expected",l)}();break}A();var r=c(58),n=(r||(T(d[l])?s=D(s,":"):u()),o());n||(r?s+="null":u())}return d.charCodeAt(l)===a?(s+="}",l++):s=D(s,"}"),!0}}()||function(){if(91!==d.charCodeAt(l))return!1;{s+="[",l++,A();let t=!0;for(;l<d.length&&93!==d.charCodeAt(l);){t?t=!1:c(44)||(s=D(s,","));var e=o();if(!e){s=B(s,",");break}}return 93===d.charCodeAt(l)?(s+="]",l++):s=D(s,"]"),!0}}()||g()||function(){var t=l;if(45===d.charCodeAt(l)&&(l++,f(t)))return!0;for(;k(d.charCodeAt(l));)l++;if(46===d.charCodeAt(l)){if(l++,f(t))return!0;for(;k(d.charCodeAt(l));)l++}if(101===d.charCodeAt(l)||69===d.charCodeAt(l)){if(l++,45!==d.charCodeAt(l)&&43!==d.charCodeAt(l)||l++,f(t))return!0;for(;k(d.charCodeAt(l));)l++}{var e;if(l>t)return t=d.slice(t,l),e=/^0\d/.test(t),s+=e?`"${t}"`:t,!0}return!1}()||r("true","true")||r("false","false")||r("null","null")||r("True","true")||r("False","false")||r("None","null")||i();return A(),t}function A(){l;let t=e();for(;t=(t=function(){if(47===d.charCodeAt(l)&&42===d.charCodeAt(l+1)){for(;l<d.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(d,l);)l++;l+=2}else{if(47!==d.charCodeAt(l)||47!==d.charCodeAt(l+1))return!1;for(;l<d.length&&d.charCodeAt(l)!==b;)l++}return!0}())&&e(););l}function e(){let t="";for(var e,r;(e=E(d.charCodeAt(l)))||(r=d.charCodeAt(l))===h||r>=O&&r<=N||r===J||r===S||r===j;)t+=e?d[l]:" ",l++;return 0<t.length&&(s+=t,!0)}function c(t){return d.charCodeAt(l)===t&&(s+=d[l],l++,!0)}function C(){92===d.charCodeAt(l)&&l++}function g(t){t=0<arguments.length&&void 0!==t&&t;let e=92===d.charCodeAt(l);if(e&&(l++,e=!0),R(d.charCodeAt(l))){const h=F(d.charCodeAt(l))?F:z(d.charCodeAt(l))?z:q(d.charCodeAt(l))?q:U;for(var r=l,n=s,o=(s+='"',l++,t?t=>m(d[t]):t=>h(d.charCodeAt(t)));l<d.length&&!o(l);){if(92===d.charCodeAt(l)){var c=d.charAt(l+1);if(void 0!==L[c])s+=d.slice(l,l+2),l+=2;else if("u"===c){if(!(I(d.charCodeAt(l+2))&&I(d.charCodeAt(l+3))&&I(d.charCodeAt(l+4))&&I(d.charCodeAt(l+5)))){i=void 0;var i=l;let t=i+2;for(;/\w/.test(d[t]);)t++;i=d.slice(i,t);throw new v(`Invalid unicode character "${i}"`,l)}s+=d.slice(l,l+6),l+=6}else s+=c,l+=2}else{var f,i=d.charAt(l),c=d.charCodeAt(l);if(c===$&&92!==d.charCodeAt(l-1))s+="\\"+i;else if((f=c)===b||f===w||f===p||f===x||f===y)s+=K[i];else{if(!(32<=(f=c)&&f<=1114111))throw f=void 0,f=i,new v("Invalid character "+JSON.stringify(f),l);s+=i}l++}e&&C()}var u=R(d.charCodeAt(l));if(!(u&&(l+1>=d.length||m(function(t,e){let r=e;for(;E(t.charCodeAt(r));)r++;return t.charAt(r)}(d,l+1))))&&!t)return l=r,s=n,g(!0);u?(s+='"',l++):s=D(s,'"');{let t=!1;A();for(;43===d.charCodeAt(l);){t=!0,l++,A();var a=(s=B(s,'"',!0)).length;g(),s=function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(s,a,1)}t}return!0}return!1}function r(t,e){return d.slice(l,l+t.length)===t&&(s+=e,l+=t.length,!0)}function i(){for(var t=l;l<d.length&&!m(d[l]);)l++;if(l>t){if(40===d.charCodeAt(l))l++,o(),41===d.charCodeAt(l)&&(l++,59===d.charCodeAt(l))&&l++;else{for(;E(d.charCodeAt(l-1))&&0<l;)l--;t=d.slice(t,l);s+="undefined"===t?"null":JSON.stringify(t),d.charCodeAt(l)===$&&l++}return!0}}function n(t){if(!k(d.charCodeAt(l)))throw t=d.slice(t,l),new v(`Invalid number '${t}', expecting a digit `+(d[l]?`but got '${d[l]}'`:"but reached end of input"),l)}function f(t){if(l>=d.length)return s+=d.slice(t,l)+"0",1;n(t)}function u(){throw new v("Colon expected",l)}}}); | ||
]`}}else t&&(s=B(s,","));for(;d.charCodeAt(l)===a||93===d.charCodeAt(l);)l++,A();if(l>=d.length)return s;throw new v("Unexpected character "+JSON.stringify(d[l]),l);function c(){A();var t=function(){if(123!==d.charCodeAt(l))return!1;{s+="{",l++,A();let e=!0;for(;l<d.length&&d.charCodeAt(l)!==a;){let t;if(e?(t=!0,e=!1):((t=i(44))||(s=D(s,",")),A()),!(g()||f())){d.charCodeAt(l)===a||123===d.charCodeAt(l)||93===d.charCodeAt(l)||91===d.charCodeAt(l)||void 0===d[l]?s=B(s,","):function(){throw new v("Object key expected",l)}();break}A();var r=i(58),n=l>=d.length,o=(r||(T(d[l])||n?s=D(s,":"):u()),c());o||(r||n?s+="null":u())}return d.charCodeAt(l)===a?(s+="}",l++):s=D(s,"}"),!0}}()||function(){if(91!==d.charCodeAt(l))return!1;{s+="[",l++,A();let t=!0;for(;l<d.length&&93!==d.charCodeAt(l);){t?t=!1:i(44)||(s=D(s,","));var e=c();if(!e){s=B(s,",");break}}return 93===d.charCodeAt(l)?(s+="]",l++):s=D(s,"]"),!0}}()||g()||function(){var t=l;if(45===d.charCodeAt(l)&&(l++,o(t)))return!0;for(;k(d.charCodeAt(l));)l++;if(46===d.charCodeAt(l)){if(l++,o(t))return!0;for(;k(d.charCodeAt(l));)l++}if(101===d.charCodeAt(l)||69===d.charCodeAt(l)){if(l++,45!==d.charCodeAt(l)&&43!==d.charCodeAt(l)||l++,o(t))return!0;for(;k(d.charCodeAt(l));)l++}{var e;if(l>t)return t=d.slice(t,l),e=/^0\d/.test(t),s+=e?`"${t}"`:t,!0}return!1}()||r("true","true")||r("false","false")||r("null","null")||r("True","true")||r("False","false")||r("None","null")||f();return A(),t}function A(){l;let t=e();for(;t=(t=function(){if(47===d.charCodeAt(l)&&42===d.charCodeAt(l+1)){for(;l<d.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(d,l);)l++;l+=2}else{if(47!==d.charCodeAt(l)||47!==d.charCodeAt(l+1))return!1;for(;l<d.length&&d.charCodeAt(l)!==b;)l++}return!0}())&&e(););l}function e(){let t="";for(var e,r;(e=E(d.charCodeAt(l)))||(r=d.charCodeAt(l))===h||r>=O&&r<=N||r===J||r===S||r===j;)t+=e?d[l]:" ",l++;return 0<t.length&&(s+=t,!0)}function i(t){return d.charCodeAt(l)===t&&(s+=d[l],l++,!0)}function C(){92===d.charCodeAt(l)&&l++}function g(t){t=0<arguments.length&&void 0!==t&&t;let e=92===d.charCodeAt(l);if(e&&(l++,e=!0),R(d.charCodeAt(l))){const h=F(d.charCodeAt(l))?F:z(d.charCodeAt(l))?z:q(d.charCodeAt(l))?q:U;for(var r=l,n=s,o=(s+='"',l++,t?t=>m(d[t]):t=>h(d.charCodeAt(t)));l<d.length&&!o(l);){if(92===d.charCodeAt(l)){var c=d.charAt(l+1);if(void 0!==L[c])s+=d.slice(l,l+2),l+=2;else if("u"===c){if(!(I(d.charCodeAt(l+2))&&I(d.charCodeAt(l+3))&&I(d.charCodeAt(l+4))&&I(d.charCodeAt(l+5)))){i=void 0;var i=l;let t=i+2;for(;/\w/.test(d[t]);)t++;i=d.slice(i,t);throw new v(`Invalid unicode character "${i}"`,l)}s+=d.slice(l,l+6),l+=6}else s+=c,l+=2}else{var f,i=d.charAt(l),c=d.charCodeAt(l);if(c===$&&92!==d.charCodeAt(l-1))s+="\\"+i;else if((f=c)===b||f===w||f===p||f===x||f===y)s+=K[i];else{if(!(32<=(f=c)&&f<=1114111))throw f=void 0,f=i,new v("Invalid character "+JSON.stringify(f),l);s+=i}l++}e&&C()}var u=R(d.charCodeAt(l));if(!(u&&(l+1>=d.length||m(function(t,e){let r=e;for(;E(t.charCodeAt(r));)r++;return t.charAt(r)}(d,l+1))))&&!t)return l=r,s=n,g(!0);u?(s+='"',l++):s=D(s,'"');{let t=!1;A();for(;43===d.charCodeAt(l);){t=!0,l++,A();var a=(s=B(s,'"',!0)).length;g(),s=function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(s,a,1)}t}return!0}return!1}function r(t,e){return d.slice(l,l+t.length)===t&&(s+=e,l+=t.length,!0)}function f(){for(var t=l;l<d.length&&!m(d[l]);)l++;if(l>t){if(40===d.charCodeAt(l))l++,c(),41===d.charCodeAt(l)&&(l++,59===d.charCodeAt(l))&&l++;else{for(;E(d.charCodeAt(l-1))&&0<l;)l--;t=d.slice(t,l);s+="undefined"===t?"null":JSON.stringify(t),d.charCodeAt(l)===$&&l++}return!0}}function n(t){if(!k(d.charCodeAt(l)))throw t=d.slice(t,l),new v(`Invalid number '${t}', expecting a digit `+(d[l]?`but got '${d[l]}'`:"but reached end of input"),l)}function o(t){if(l>=d.length)return s+=d.slice(t,l)+"0",1;n(t)}function u(){throw new v("Colon expected",l)}}}); |
{ | ||
"name": "jsonrepair", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Repair broken JSON documents", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -17,2 +17,3 @@ # jsonrepair | ||
- Add missing closing brackets | ||
- Repair truncated JSON | ||
- Replace single quotes with double quotes | ||
@@ -19,0 +20,0 @@ - Replace special quote characters like `“...”` with regular double quotes |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260664
2404
193