json keys with spaces

I need help with a JSON structure I am working with:

data:
{
First Name: "Robert",
Last Name: "Smith"
}

I'm trying to access the data using javascript like this: "data.First Name" I know this is incorrect syntax. How can I extract the information from the current structure?

Thanks!

Answer №1

JSON must have field names enclosed in double quotes, unlike what you provided which is not valid JSON.

{
    "info" : {
        "First Name": "Robert",
        "Last Name": "Smith"
    }
}

Once parsed, you can access the First Name field using obj.info["First Name"].

Although your input resembles a JS object literal (which is still invalid), you can stringify the property names to achieve the same result.

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

Firebase is providing inconsistent data types in JSON responses

Our team is facing an issue while trying to fetch data from FireBase in the form of a 2D array. Despite setting everything up in the same manner, we are encountering different data types in the JSON response. Data provided: [ {"0":24, "1& ...

Tips for establishing a connection with the MovieDB API web service

As a beginner in the world of web services, I am currently in the learning phase. Unfortunately, there is not much online content available that provides information on how to use the MovieDB API web service. For now, my main focus is on trying to display ...

Obtain the ThreeJS coordinates for shadow pixel positions in a 3D environment

In my ThreeJS project, I have created a scene where a gold object casts a curved shadow on a spherical surface. The shadow is achieved by rendering only the backside of the sphere and using a point light at the center of the eye model. I am looking to extr ...

Using the active class feature in React Router

Hey there! I've been working with react router v6 and using NavLink to move between components. I've been trying to figure out how to add a custom active class in NavLink, but the method I tried isn't working. Here is what I attempted: <N ...

Modify one object within another object while maintaining all other parameters unchanged

My data structure looks like this: { firstname: '', company: {id: '', name: ''}, nextAction: { by: '', type: {id: '', name: ''} } } With the followin ...

Creating a Json autocomplete feature for category

Looking to implement categorized jquery autocomplete with Rails. Successfully retrieved JSON response: ["Air Canada to appeal Quebec court ruling on Aveos","First Nations meeting with PM in jeopardy","Neanderthals, humans may have missed each other","New ...

Tips for ensuring that the horizontal scroll bar remains consistently positioned at the bottom of the screen

There are two div sections on a page, with one positioned on the left and the other on the right. The div on the right contains multiple dynamically generated tags which necessitate a horizontal scroll bar (overflow:auto). This causes the div's height ...

Determine total and showcase it as the range slider is adjusted

Seeking to calculate and present the result of three range sliders. The equation I aim to showcase is: KM driven per year * Avg KM/100L / Price of fuel I have managed to display each slider's individual values, but I am uncertain about how to show t ...

"Troubleshooting: Sending null values through Jquery ajax to an MVC controller

The issue: I am facing a challenge with saving events in a calendar through ajax by sending the content to my controller function. Despite my efforts, I constantly see null values being passed to my database. Upon inspecting the Network tools console log ...

Tips for successfully implementing Typeahead with Bloodhound and a JSON response

Looking for guidance on integrating typeahead.js with bloodhound.js to leverage my JSON data structure. My goal is to implement a type-ahead feature utilizing a preloaded JSON object that remains accessible. Here's the breakdown: The Data/All URL res ...

Can you provide instructions on how to replace the icon within the TablePagination element in MUI?

I'm currently working on a React project where I've implemented the MUI component known as TablePagination This TablePagination component is situated within the Table component, just like in the image provided below. https://i.stack.imgur.com/B ...

Guide on testing code within $(window).on("load", function() {}); with Jasmine

Here is a script written in JavaScript that appends a DIV element to the page on load and then hides it after 3 seconds. var elementHandler = { initialize: function() { var self = this; $(window).on("load", function() { (function ($) ...

Having trouble with the functionality of the cascading menu?

I am having trouble with a drop-down menu. The first level works fine, but I can't seem to get the second level of the menu to display. Appreciate any help you can offer. Thank you. javascript <script type="text/javascript"> $(document).ready( ...

Transform JSON-formatted NSURLRequest into a String in Swift

My process involves sending a JSON structured string via NSURLRequest, removing the urlscheme prefix, converting it to JSON, and then manipulating it as needed. urlscheme://{"Type":"photo","Name":"Photo13"} To convert NSURLRequest to a string, I used the ...

Import GraphQL data in gatsby-browser.js (or alternative method, if available)

I am currently facing a challenge with running a GraphQL query within the context of replaceRouterComponent in gatsby-browser.js (reference to Gatsby browser API). However, I am able to access data from Contentful. If there are alternative approaches or s ...

How to automatically disable a button in reactjs when the input field is blank

I have a component called Dynamic Form that includes input fields. The challenge I am facing is how to disable the submit button when these input fields are empty, although the validateResult function fails to return false. import cn from "classname ...

I am looking to display a single column in a SQL query as a JSON array containing all the child values

My query involves retrieving various fields from a product table and also assigning multiple tags to each product using a ProductTagMapping table. I want to include a Tags column in my output that contains a JSON Array of the associated Tag Names from a Pr ...

Enhancing Request JSON Body Validation in Next.js 14 API Handler

I'm currently in the process of developing an API for my iOS application using Next.js 14. I have managed to get it up and running successfully, however, I am facing some challenges when it comes to properly validating the body of a request. ESLint is ...

Conceal the slider thumb within the material-ui framework

I've been attempting to conceal the slide thumb, initially without using a library. However, I started considering utilizing material-ui as it might make the process easier. Hence, I'm seeking assistance here. Below is my code snippet: import * ...

Steps for repairing the encoding of a string in JavaScript

I have encountered a broken string from another software source and I am attempting to repair its encoding using JavaScript, but I seem to be missing a crucial step. Here is an example of the broken string: Détecté à lors ô ù The desir ...