Easily! With Almost No-Code!!!

Posted at

Given the following JSON:
{
  "@context":           "http://schema.org"
, "@type":              "WebSite"
, "url":                "https://icompile.eladkarako.com/"
, "name":               "Elad Karako Computer Science Corner"
, "alternateName":      "iCompile Is A Tech-Personal Blog Written By Elad Karako ☕︎"
, "logo":               "https://icompile.eladkarako.com/img/apple-touch-icon.png"
, "potentialAction": {  "@type": "SearchAction"
                     ,  "target": "https://icompile.eladkarako.com/?s={search_term_string}"
                     ,  "query-input": "required name=search_term_string"
                     }
}



  1. First, store the raw string somewhere, for example, get it from a textarea (its value),
    say you've put it into a variable named CONTENT.

  2. Next, remove all line-feed/break characters for safe/compatibility with the JSON parsing method we'll use next.
    Simply use: CONTENT = CONTENT.replace(/[\\
    ]+/g," ");
    (replacing things with SPACE is safer than removing them...)
    You'll end up with one-line:
    '{   "@context":           "http://schema.org" , "@type":              "WebSite" , "url":                "https://icompile.eladkarako.com/" , "name":               "Elad Karako Computer Science Corner" , "alternateName":      "iCompile Is A Tech-Personal Blog Written By Elad Karako ☕︎" , "logo":               "https://icompile.eladkarako.com/img/apple-touch-icon.png" , "potentialAction": {  "@type": "SearchAction"                      ,  "target": "https://icompile.eladkarako.com/?s={search_term_string}"                      ,  "query-input": "required name=search_term_string"                      } }'
    



  3. Use
    CONTENT = JSON.parse('{   "@context":           "http://schema.org" , "@type":              "WebSite" , "url":                "https://icompile.eladkarako.com/" , "name":               "Elad Karako Computer Science Corner" , "alternateName":      "iCompile Is A Tech-Personal Blog Written By Elad Karako ☕︎" , "logo":               "https://icompile.eladkarako.com/img/apple-touch-icon.png" , "potentialAction": {  "@type": "SearchAction"                      ,  "target": "https://icompile.eladkarako.com/?s={search_term_string}"                      ,  "query-input": "required name=search_term_string"                      } }');

    which will convert it to a javascript-object.


  4. And finally use something like CONTENT = JSON.stringify(CONTENT, null, 0);, to get the string.
    You'll end up with something like:
    '{"@context":"http://schema.org","@type":"WebSite","url":"https://icompile.eladkarako.com/","name":"Elad Karako Computer Science Corner","alternateName":"iCompile Is A Tech-Personal Blog Written By Elad Karako ☕︎","logo":"https://icompile.eladkarako.com/img/apple-touch-icon.png","potentialAction":{"@type":"SearchAction","target":"https://icompile.eladkarako.com/?s={search_term_string}","query-input":"required name=search_term_string"}}'
    


  5. DONE!
    ..Enjoy!!!

', 'JavaScript Ninja - Minify JSON