How to stringify entire JavaScript file code as JSON value Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow to validate an email address in JavaScript?How do JavaScript closures work?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How can I get query string values in JavaScript?How do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Replacing HDD with SSD; what about non-APFS/APFS?

Using "nakedly" instead of "with nothing on"

Cold is to Refrigerator as warm is to?

Working around an AWS network ACL rule limit

How do you clear the ApexPages.getMessages() collection in a test?

Unable to start mainnet node docker container

Do we know why communications with Beresheet and NASA were lost during the attempted landing of the Moon lander?

New Order #5: where Fibonacci and Beatty meet at Wythoff

Stars Make Stars

What is the electric potential inside a point charge?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Determine whether f is a function, an injection, a surjection

Problem when applying foreach loop

Why use gamma over alpha radiation?

Slither Like a Snake

What is the largest species of polychaete?

Strange behaviour of Check

Need a suitable toxic chemical for a murder plot in my novel

How can I make names more distinctive without making them longer?

Estimated State payment too big --> money back; + 2018 Tax Reform

What LEGO pieces have "real-world" functionality?

When communicating altitude with a '9' in it, should it be pronounced "nine hundred" or "niner hundred"?



How to stringify entire JavaScript file code as JSON value



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow to validate an email address in JavaScript?How do JavaScript closures work?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How can I get query string values in JavaScript?How do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















let's say I have some JavaScript code taken from a file stored in a string, and I want to send that to a server, how can I stringify it?



For example, I want the result of something like this (which I stringified from the babelJS transform.code result, which looks like it automatically flattened the javascript and added in all the " breaks, how can I Do this with my own JavaScript code string?):



 "compiled JavaScript":"code":""use strict";nnfunction _classCallCheck(instance, Constructor) if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); nnvar f = function f(x) ;nnvar Coybster = function Coybster() n _classCallCheck(this, Coybster);n;","error":null









share|improve this question

















  • 1





    JSON.stringify(code)? It is normal that quotes are escaped.

    – trincot
    Mar 22 at 7:45







  • 1





    Your result there is valid JSON (or, if not JSON, it's an object which can be serialized ^) - you should be able to send it around anywhere safely

    – CertainPerformance
    Mar 22 at 7:45












  • Where is this JS coming from? If it's retrieved via ajax, then it's already a string that can be sent to server. If it's a JS function, then you can stringify it with toString method (but your example has multiple statements)

    – eithed
    Mar 22 at 7:49











  • JavaScript code - code can not be converted to JSON

    – Jaromanda X
    Mar 22 at 7:50











  • @CertainPerformance the example I brought is copied from babelJS, thats the result I WANT to get in my own string

    – bluejayke
    Mar 22 at 7:56

















-2















let's say I have some JavaScript code taken from a file stored in a string, and I want to send that to a server, how can I stringify it?



For example, I want the result of something like this (which I stringified from the babelJS transform.code result, which looks like it automatically flattened the javascript and added in all the " breaks, how can I Do this with my own JavaScript code string?):



 "compiled JavaScript":"code":""use strict";nnfunction _classCallCheck(instance, Constructor) if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); nnvar f = function f(x) ;nnvar Coybster = function Coybster() n _classCallCheck(this, Coybster);n;","error":null









share|improve this question

















  • 1





    JSON.stringify(code)? It is normal that quotes are escaped.

    – trincot
    Mar 22 at 7:45







  • 1





    Your result there is valid JSON (or, if not JSON, it's an object which can be serialized ^) - you should be able to send it around anywhere safely

    – CertainPerformance
    Mar 22 at 7:45












  • Where is this JS coming from? If it's retrieved via ajax, then it's already a string that can be sent to server. If it's a JS function, then you can stringify it with toString method (but your example has multiple statements)

    – eithed
    Mar 22 at 7:49











  • JavaScript code - code can not be converted to JSON

    – Jaromanda X
    Mar 22 at 7:50











  • @CertainPerformance the example I brought is copied from babelJS, thats the result I WANT to get in my own string

    – bluejayke
    Mar 22 at 7:56













-2












-2








-2








let's say I have some JavaScript code taken from a file stored in a string, and I want to send that to a server, how can I stringify it?



For example, I want the result of something like this (which I stringified from the babelJS transform.code result, which looks like it automatically flattened the javascript and added in all the " breaks, how can I Do this with my own JavaScript code string?):



 "compiled JavaScript":"code":""use strict";nnfunction _classCallCheck(instance, Constructor) if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); nnvar f = function f(x) ;nnvar Coybster = function Coybster() n _classCallCheck(this, Coybster);n;","error":null









share|improve this question














let's say I have some JavaScript code taken from a file stored in a string, and I want to send that to a server, how can I stringify it?



For example, I want the result of something like this (which I stringified from the babelJS transform.code result, which looks like it automatically flattened the javascript and added in all the " breaks, how can I Do this with my own JavaScript code string?):



 "compiled JavaScript":"code":""use strict";nnfunction _classCallCheck(instance, Constructor) if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); nnvar f = function f(x) ;nnvar Coybster = function Coybster() n _classCallCheck(this, Coybster);n;","error":null






javascript babeljs babel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 7:43









bluejaykebluejayke

3782519




3782519







  • 1





    JSON.stringify(code)? It is normal that quotes are escaped.

    – trincot
    Mar 22 at 7:45







  • 1





    Your result there is valid JSON (or, if not JSON, it's an object which can be serialized ^) - you should be able to send it around anywhere safely

    – CertainPerformance
    Mar 22 at 7:45












  • Where is this JS coming from? If it's retrieved via ajax, then it's already a string that can be sent to server. If it's a JS function, then you can stringify it with toString method (but your example has multiple statements)

    – eithed
    Mar 22 at 7:49











  • JavaScript code - code can not be converted to JSON

    – Jaromanda X
    Mar 22 at 7:50











  • @CertainPerformance the example I brought is copied from babelJS, thats the result I WANT to get in my own string

    – bluejayke
    Mar 22 at 7:56












  • 1





    JSON.stringify(code)? It is normal that quotes are escaped.

    – trincot
    Mar 22 at 7:45







  • 1





    Your result there is valid JSON (or, if not JSON, it's an object which can be serialized ^) - you should be able to send it around anywhere safely

    – CertainPerformance
    Mar 22 at 7:45












  • Where is this JS coming from? If it's retrieved via ajax, then it's already a string that can be sent to server. If it's a JS function, then you can stringify it with toString method (but your example has multiple statements)

    – eithed
    Mar 22 at 7:49











  • JavaScript code - code can not be converted to JSON

    – Jaromanda X
    Mar 22 at 7:50











  • @CertainPerformance the example I brought is copied from babelJS, thats the result I WANT to get in my own string

    – bluejayke
    Mar 22 at 7:56







1




1





JSON.stringify(code)? It is normal that quotes are escaped.

– trincot
Mar 22 at 7:45






JSON.stringify(code)? It is normal that quotes are escaped.

– trincot
Mar 22 at 7:45





1




1





Your result there is valid JSON (or, if not JSON, it's an object which can be serialized ^) - you should be able to send it around anywhere safely

– CertainPerformance
Mar 22 at 7:45






Your result there is valid JSON (or, if not JSON, it's an object which can be serialized ^) - you should be able to send it around anywhere safely

– CertainPerformance
Mar 22 at 7:45














Where is this JS coming from? If it's retrieved via ajax, then it's already a string that can be sent to server. If it's a JS function, then you can stringify it with toString method (but your example has multiple statements)

– eithed
Mar 22 at 7:49





Where is this JS coming from? If it's retrieved via ajax, then it's already a string that can be sent to server. If it's a JS function, then you can stringify it with toString method (but your example has multiple statements)

– eithed
Mar 22 at 7:49













JavaScript code - code can not be converted to JSON

– Jaromanda X
Mar 22 at 7:50





JavaScript code - code can not be converted to JSON

– Jaromanda X
Mar 22 at 7:50













@CertainPerformance the example I brought is copied from babelJS, thats the result I WANT to get in my own string

– bluejayke
Mar 22 at 7:56





@CertainPerformance the example I brought is copied from babelJS, thats the result I WANT to get in my own string

– bluejayke
Mar 22 at 7:56












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294968%2fhow-to-stringify-entire-javascript-file-code-as-json-value%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294968%2fhow-to-stringify-entire-javascript-file-code-as-json-value%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript