Forum Academy Marketplace Showcase Pricing Features

Escape user-input text to create valid JSON string

This is what @sean.paley also sugested in Escape strings in body of API call. Re-posting here as an idea for a nice feature that it’s difficult to accomplish otherwise. I have used find & replace with some success, but there is a lot you need to take into account. See

Like this package

There is JSON.stringify(mydodgystuff) available in the browser’s javascript, do you need to escape more than that does?

Partially answering my own question, … there is a bunch of test cases in here, for some gory details of escaping : )

Sorry for my ignorance, but how do I access JSON.stringify() from Bubble?

It’s definitely coding … but not necessarily a lot of it.

With an input field with placeholder “JSON-string-input”, the HTML code would be something like:
<script type="text/javascript"> if ("pageloaded" === "yes" && "mystring-is-not-empty" === "yes") { $('.bubble-element .Input[placeholder="JSON-string-input"]').val(JSON.stringify("mystring.value")).change(); } </script>

Replacing pageloaded and mystring-is-not-empty with dynamic values.

If you try it, I’ll help get it working.

Some of us are fiddling with the new element templates, so this will become a bit easier soon.

just this … in a

module.exports = function(context, cb) {
cb(null, JSON.stringify(context.query.jvalue));

Thanks @NigelG and @mishav, I will try it out next week and post an update here with some feedback.

A hint as to which method is appropriate, using an API is better if you want the data to stay on the server. Using the browser javascript saves the roundtrip of an extra API call, if using the JSON in response to a user action.