Is there a way to extract Json from a Scala Json string and store it in a JS variable?

Currently, I am utilizing the Play framework and attempting to transmit a Json string from the server as a parameter to a Scala template.

@(aj: String)
@import play.api.libs.json.Json
<!DOCTYPE html>
<html lang="en">
   <body>
      <div id="container">
        @aj
      </div>

    <script>
       var <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b7b4eb969ca5b9b8f8a2b99ca5b9b8">[email protected]</a>(aj);
       var a = JSON.parse(ab);
    </script>
    </body>
 </html>

The output I am currently getting is that the Json String is being displayed inside the container div. However, I am encountering difficulties when trying to extract the Json from 'aj' into a javascript variable. Any assistance on this matter would be greatly appreciated.

Answer â„–1

To achieve this, you have the option to use:

<script>
var data = @Html(aj),
object = JSON.parse(data);
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ravaging a JSON array in Delphi

This piece of code is causing a memory leak. Can you suggest the correct approach to tackle this issue? JSONArrayObject := TJSONArray.Create; try JSONArrayObject := TJSONObject.ParseJSONVal ...

Looking to switch from using HTTP to HTTPS in Node.js on localhost... encountering a few error messages

I'm facing an issue with integrating my code into the entire localhost project "app." It works fine with a simple implementation: https.createServer(options) But when I try to run it within the "app" project using the following setup: const server = ...

Attempting to retrieve XML/JSON

I am struggling with extracting the first 15 words from a file using the API. I have attempted to do it with both XML and JSON, but keep encountering this error: XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on th ...

I encountered an issue where the IDs did not match while using an array to update the MYSQL database

Currently, I am facing an issue while looping through an array in node JS to update a MYSQL database. The problem arises because the array starts at 0, whereas my auto-incrementing database starts at 1. This misalignment offsets the entire database by on ...

When the user hits the enter key, automatically submit a form without the need for

Is it possible to submit a form on enter using type="button"? Here are my input fields: <input type="text" id = "login-user" class="form-control log-input" placeholder="Username" required="required"> <input type="password" id="login-password" clas ...

Ajax causing unreliable posts

I am facing an issue with sending and receiving data in my mobile application. I currently use the jquery $.post function, but it seems to be quite unreliable. Issue: Occasionally, about 1 out of 10 times, the POST request is sent successfully, but the ca ...

Generating text upon clicking by utilizing vue apex charts dataPointIndex

Is there a way to populate a text area on click from an Apex chart? The code pen provided below demonstrates clicking on the bar and generating an alert with the value from the chart. Instead of displaying this value in an alert, I am looking to place it o ...

Is there a way to ensure that @angular/core is utilizing the most up-to-date version of zone.js in its peerDependencies configuration?

This code passes the test, but there is an issue: it('should successfully retrieve data when getDownloadProgress() is called', (done: DoneFn) => { let response = { 'process': {}, 'success': 'success ...

What is the best way to verify the success or error callbacks of an AJAX request?

We have the option to include AJAX callback functions in various sections: $.ajax(url,{ data:data, ..., success:successCallback1, error:errorCallback1 }) .success(successCallback2) .error(errorCallback2) .done(successCallback3) .fail(errorCallb ...

Develop a Playwright test script that includes fetch requests

My goal is to create an end-to-end test using Playwright for a website built with React. The website functions as follows: Upon initial rendering, it fetches a random fact from one API and then uses the first three words of that fact to fetch a random p ...

Where can I find the link to access three.js on the internet?

Currently working on a JavaScript application within Google App Engine using three.js, but struggling to find the URL for online inclusion in my document. Uploading the entire large-sized three.js package is not ideal, so I'm looking for a way to obta ...

What is causing this function to incorrectly increase decimal values?

Similar Questions: Investigating JavaScript’s Floating-Point Math Exploring the Concept of Rounding a Float in JavaScript What could be causing this function to inaccurately increase decimal values? My aim is to display only one decimal place. ...

Extract specific data from JSON objects

I have a JSON string that I need to parse on the client side in order to extract data for three different column names (MAT_ETHNICITY, PAT_ETHNICITY, SEX). My goal is to populate drop down lists with the values. Should I handle this by making three separ ...

Ways to handle parsing of curly brackets JSON in Google Apps Script?

How can I use Google Apps Script to parse through the output of an API and convert it into a table in Google Sheets? I attempted the following code, but it only returns Null values. var response = UrlFetchApp.fetch(url, options); var text = response.getCo ...

Use the lodash chunk method to split a mapped array into two separate arrays

Looking to organize some data into tables? I have a dataset from an API that you might find helpful. [ { date: "1/11", data: [ { camera: "camera 1", count: 10 }, { camera: "camera 2", count: 20 ...

Guide to sending and receiving JSON data using XAMPP PHP

Currently, my XAMPP 7.1.10-0 server is up and running with the following index.php file: <?php if(isset($_POST["username"])) { echo $_POST; header("Location:getbooks.php"); exit; } else { echo file_get_conten ...

Error in Vue.js when attempting to push using the sendMessage method

I am facing an issue with the following method: props: ['convId'], data() { return { messages: [], newMessage: '' }; }, methods: { sendMessage() { axios.post('/send ...

The FlatList component will only trigger a re-render once the list has been scrolled

I need help with updating a FlatList in my app. Currently, the list is populated by an array stored in the component's state and can be filtered using a filtering function that updates the state with a new filtered array. However, I have noticed that ...

Guide to creating a fully clickable Card component with Material UI and React JS

Currently in my React project, I am utilizing Material UI Next. Within this framework, I have implemented the Card component that contains both an image (Card Media) and text (Card Text), with a button located below the text. My inquiry pertains to makin ...

Obtaining weather information for a particular date through wunderground

Today marks my first experience using this wunderground service. My goal is to retrieve weather data under the following circumstances: Note : Today Date :2014-02-03 I am looking to access weather data ranging from 2014-01-21 to 2014-01-31, which fal ...