Converting an AJAX string response into JSON: A step-by-step guide

When I receive my EjB response using AJAX, it looks like this:

"{'Active':{'123','456','789'},'Inactive':{'111','222','333'}}"

My goal is to convert the string above into JSON objects that can be used in JavaScript to create a map.

Alternatively,

I am looking to convert the same string into the following format in JavaScript:

var active = ["123", "456", "789"]; var inactive = ["111", "222", "333"];

Just a reminder: I am utilizing AJAX in JS for this operation.

Answer №1

const jsonData = JSON.parse(apiResponse);

apiResponse contains the JSON data retrieved from an ajax request, and jsonData is the parsed result you need.

Answer №2

const jsonData = "{'Active':{'123','456','789'},'Inactive':{'111','222','333'}}"

const parsedData = JSON.parse(jsonData)

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

Developing an HTML table with the power of JavaScript and JSON

I am having difficulty creating an HTML table using JavaScript with JSON input. In my code, I'm using a placeholder in the HTML that will be filled by a innerHTML call in Javascript: for (var i = 0; i < json.data.length; i++) { listItem = json. ...

Saving a JSON object to multiple JSON objects in TypeScript - The ultimate guide

Currently, I am receiving a JSON object named formDoc containing data from the backend. { "components": [ { "label": "Textfield1", "type": "textfield", "key": "textfield1", ...

The setInterval function with a time interval set to 1ms does not appear to function exactly as a 1ms delay

I'm attempting to measure the duration of a file download using an HTTPRequest as seen below: function getFile() { 'use strict'; var url = "data.bin"; var rawFile = new XMLHttpRequest(); var timer_var = setInterval( theTimer ...

The functionality of the bootstrap tab('show') is not functioning properly when applied to dynamically loaded tab content

I am currently utilizing ASP.NET MVC along with Bootstrap 3 Within my main view, I have implemented Bootstrap tabs as shown below: <div class="row"> <div class="tabs-container"> <ul class="nav nav-tabs" id="test"> ...

What is the best way to send the value of a Select component from a child to a parent component in

Users have the ability to select a category, triggering the appearance of another dropdown menu based on their selection. I have created a separate component in a different file (.js) to handle this second dropdown. While I can see the data, I am wondering ...

Redirecting pages using an Ajax script in JavaScript

Unfortunately, I am unable to use a *.php extension for my page due to unforeseen circumstances. This has led me to consider using *.html instead and implementing conditional redirection using javascript/Ajax to call a PHP script that can evaluate the cond ...

Ways to help parents disregard events initiated by their children

I have a situation where clicking on a child element should not trigger the parent element, but using event.stopPropagation() is not an option due to other event listeners waiting for the click event. Specifically, when clicking on the dropdown of parent1 ...

Loop through the data string in Ajax using a For Loop to populate it

I am currently working on a loop that inserts select tags based on the number of rows. Each select tag will have an ID like selID0, selID1, selID2, and so on. My goal is to call an AJAX function to determine which tag is not selected when the submit button ...

iOS AFNetworking post request generates an error: Request failed due to a bad request (400)

When I use AFNetworking to make a post web service call, I consistently receive the following response: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" Below is my code snippet: NSURLSessionConfig ...

A stationary webpage nested within a lively pathway on NuxtJS

I have a Nuxt app with a list of cars available at: /cars. You can select a specific car at /cars/:id. I would like to have a toolbar that routes to different views such as: /cars/:id/routes, /cars/:id/drivers, etc. Within the /cars/:id page, I have creat ...

Checking with jQuery Validate: displaying an error message if input matches a certain value

I spent 6 hours trying to figure out a solution to my issue. Currently, I am utilizing the jQuery Validation plugin. In my form, there is a password input field. When an AJAX request detects an incorrect password, another input field is set to a value of ...

Discover the top 10 entries from an array by sorting them based on the highest score

I'm struggling to extract the top 10 records from an array based on the highest score calculation using PHP. After fetching data from a table, performing the necessary calculations, and storing the results in an array called "score," I want to include ...

Error: The <Class> cannot be accessed until it has been initialized

I have a basic autoloader method that initializes and returns an instance of a class using require() The require statement includes some logic that requests information from a database and checks if the class exists in the filesystem. let elementClass = r ...

Angular JS has a unique feature of a scrollable drop-up menu that allows

https://i.sstatic.net/MOUqO.pngHere is the code snippet for my Dropup component: <div class="dropup"> <button class="btn btn-primary btn-raised dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false> ...

How to delete an array within an array in MongoDB if it exists

{ "_id" : ObjectId("5cca927ed5494b0"), "userName": "1234", "rcReviews": [{ "userName": "qwert", "finalReview": "qtrwyw", "dField": [{ "name": "t2", "status": "Not Verified", "reviewCom ...

A guide to iterating through columns and modifying variables

After scratching my head, I am on the lookout for guidance in the right direction to solve my issue. I have a Google spreadsheet with multiple rows, but I only need the script to focus on the newest row. Despite not having undergone any formal computer tr ...

A gathering focused on the pause function of a bootstrap carousel

After carefully reviewing the documentation, it seems there isn't a specific event to detect when the carousel is paused. Is there a workaround for detecting when the bootstrap carousel is paused? The carousel can be paused using various methods, and ...

Leverage the variables' values to access property

There is a way to use this possibility: let eventSelected = "333"; let bestResult = result.personal_records[eventSelected]?.single?.best //like searching like this: result.personal_records.333?.single?.best However, when deali ...

Utilizing Reactjs and Php to Send and Retrieve Form Data

I am currently working with Reactjs (Nextjs) and PHP. I am trying to send form data using Axios, but I am facing an issue where I am unable to retrieve any parameter on the API side. How can I resolve this problem? Below is my current code: const handleSu ...

The v-model for a particular field is not reflecting real-time updates like the other fields with the same datatype. I'm trying to figure out what could be causing this issue

In my specific model, there are various values that can be updated through a form on the webpage. These values include "Quantity", "Rate", "Amount", "Net rate", and more. The problem I am facing is with binding these values with my inputs using v-model. E ...