src/jPretty.js
function jPretty(obj) {
  // make sure data is a json obj
  if(typeof obj === "string") {
    obj = obj.replace(/\s/g,"");
    obj = obj.replace(/'/g,'"');
  }
  let gl;
  try {
    
    const p = JSON.parse(obj); 
    gl = obj; // already stringified
  } catch (e) { // not stringified
      if(typeof obj === "string") {
        obj = obj.replace(/([,|{|\s|])([a-zA-Z0-9]*?)([\s|]*\:)/g,'$1"$2"$3');
      }

      const s = JSON.stringify(obj);
      const k = JSON.parse(JSON.stringify(obj));
       if (k && typeof k === 'object') {
        gl = s;
      } else {
        if(typeof obj === "string") {
        //console.log("ERROR: " + );
        obj = obj.replace(/"/g,"'");
        obj = obj.replace(/'/g,'"');
        
        gl = ((obj));
        } else {
          return new Error(`jpretty: input is not recognised json: ${typeof obj}- ${JSON.stringify(obj)}`);
        }
      }
  }

  return (() => {
    let jp = prettyJson(gl); 
    if(typeof window !== 'undefined') {
      console.log("jPretty loaded in browser");
        jp = jp.replace(/\{\}/g,"<br/>{}");
    }
    return jp;
  })()
}
function jPretty(obj) {
  // make sure data is a json obj
  if(typeof obj === "string") {
    obj = obj.replace(/\s/g,"");
    obj = obj.replace(/'/g,'"');
  }
  let gl;
  try {
    
    const p = JSON.parse(obj); 
    gl = obj; // already stringified
  } catch (e) { // not stringified
      if(typeof obj === "string") {
        obj = obj.replace(/([,|{|\s|])([a-zA-Z0-9]*?)([\s|]*\:)/g,'$1"$2"$3');
      }

      const s = JSON.stringify(obj);
      const k = JSON.parse(JSON.stringify(obj));
       if (k && typeof k === 'object') {
        gl = s;
      } else {
        if(typeof obj === "string") {
        //console.log("ERROR: " + );
        obj = obj.replace(/"/g,"'");
        obj = obj.replace(/'/g,'"');
        
        gl = ((obj));
        } else {
          return new Error(`jpretty: input is not recognised json: ${typeof obj}- ${JSON.stringify(obj)}`);
        }
      }
  }

  return (() => {
    let jp = prettyJson(gl); 
    if(typeof window !== 'undefined') {
      console.log("jPretty loaded in browser");
        jp = jp.replace(/\{\}/g,"<br/>{}");
    }
    return jp;
  })()
}
function jPretty ( obj ) { // make sure data is a json obj if ( typeof obj === "string" ) { obj = obj . replace ( / \s / g , "" ) ; obj = obj . replace ( / ' / g , '"' ) ; } let gl ; try { const p = JSON . parse ( obj ) ; gl = obj ; // already stringified } catch ( e ) { // not stringified if ( typeof obj === "string" ) { obj = obj . replace ( / ([,|{|\s|])([a-zA-Z0-9]*?)([\s|]*\:) / g , '$1"$2"$3' ) ; } const s = JSON . stringify ( obj ) ; const k = JSON . parse ( JSON . stringify ( obj ) ) ; if ( k && typeof k === 'object' ) { gl = s ; } else { if ( typeof obj === "string" ) { //console.log("ERROR: " + ); obj = obj . replace ( / " / g , "'" ) ; obj = obj . replace ( / ' / g , '"' ) ; gl = ( ( obj ) ) ; } else { return new Error ( ` ${ typeof obj } ${ JSON . stringify ( obj ) } ` ) ; } } } return ( ( ) => { let jp = prettyJson ( gl ) ; if ( typeof window !== 'undefined' ) { console . log ( "jPretty loaded in browser" ) ; jp = jp . replace ( / \{\} / g , "<br/>{}" ) ; } return jp ; } ) ( ) }
Tidies up the json into a correct javascript object notation.

@param {object} obj text or object.
calls the main prettyJson module passing the json obj as argument.
Tidies up the json into a correct javascript object notation .