Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:06:11+00:00 2026-06-02T10:06:11+00:00

I have a JSON String stored in a database. In one of my JSP

  • 0

I have a JSON String stored in a database. In one of my JSP pages, I retrieve this string, and I want to be able to pass the String or the JSON object into Javascript function. The function is simply this for test purposes

function test(h){

alert(h);
}

Now I can retrieve the JSON string from the database fine, I have printed it out to the screen to ensure that it is getting it, however when I pass it in like this

        <input  type="button" 
                                name="setFontButton" 
                                value="Set" 
                                class="form_btn_primary"
                                onclick="test('<%=theJSON%>'); return false;"/>   

Nothing happens. I used firebug to check what was wrong, and it says there is invalid character.

So I then tried passing in the JSON object like so

Widget widg = mapper.readValue(testing.get(0), Widget.class);

Then pass in it

onclick="test('<%=widg%>'); return false;"/>

Now this will pass in without an error, and it alerts the object name, however I am unable to parse it. Object comes in like with the package name of where the widget class is stored like so

com.package.mode.Widget@ba8af9 

I tried using Stringify, but that doesn’t seem to work on this Jackson JSON object.

After all that failed, I tried a last resort of taking the String from the database, and encoding it in base64. However, this too fails if I do this

String test = Base64.encode(theString);

and pass that in. However if I do that, print it out to the screen, then copy what is printed out, and send that through it works, so don’t quite understand why that is.

So could someone please tell me what I am doing wrong. I have tried soo many different solutions and nothing is working.

The JSON String is stored in database like this

{
“id”:1,
“splits”:[
{
“texts”:[
{
“value”:”Test”,
“locationX”:3,
“locationY”:-153,
“font”:{
“type”:”Normal”,
“size”:”Medium”,
“bold”:false,
“colour”:”5a5a5a”,
“italics”:false
}
}
]
}
]
}

Would be very grateful if someone could point me in the direct direction!!

Edit:

Incase anyone else has same problem do this to pass the JSON from JSP to the JS function

<%=theJSON.replaceAll("\"", "\\\'")%>

That allows you to pass the JSON in,

then to get it back in JavaScript to normal JSON format

theJSON = theJSON.replace(/'/g,'"');

Should work fine

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:06:12+00:00Added an answer on June 2, 2026 at 10:06 am

    I think the combination of double quotes wrapping the onclick and the ones in your JSON may be messing you up. Think of it as if you entered the JSON manually — it would look like this:

    onclick="test('{ "id":1, "splits":[ { "texts":[ { "value":"Test", "locationX":3, "locationY":-153, "font":{ "type":"Normal", "size":"Medium", "bold":false, "colour":"5a5a5a", "italics":false } } ] } ] }'); return false;"
    

    and the opening double quote before id would actually be closing the double quote following onclick= (You should be able to verify this by looking at the page source). Try specifying the onclick as:

    onclick='test(\'<%=theJSON%>\'); return false;'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
I have a certain object type that is stored in a database. This type
I have a JSON stored in DB and I want to deserialize it into
I have a json string saved in my db. When i retrieve it from
I have a JSON string that looks like this: { package1: { type: envelope,
Whenever I have a Json string object with a space in it I get
Possible Duplicate: How to parse JSON in JavaScript I have this JSON string: [{title:
Objective: I would like to take a JSON String and pass it into JavaScript
I retrieve data from a mysql database. I want to make this data available
How to store large JSON String in cookie ? I have to use cookie

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.