What is the proper way to retrieve the value of the key "order" from this JSON object (containing semicolons in the name)?

Vijay Anand inquired about this particular matter yesterday, unfortunately, the discussion was closed before receiving any solutions:

HTTP Response:

{
  "entry": {
    "@xml:base": "https://API_PROC_SRV/",
    "@xmlns": "http://www.w3.org/2005/Atom",
    "@xmlns:m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
    "@xmlns:d": "http://schemas.microsoft.com/ado/2007/08/dataservices",
    "id": "https://API_PROC_SRV/A_Order",
    "title": {
      "@type": "text",
      "#text": "A_Order()"
    },
    "updated": "2020-02-29T07:33:28Z",
    "category": {
      "@term": "Type",
      "@scheme": "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
    },
    "link": [],
    "content": {
      "@type": "application/xml",
      "m:properties": {
        "d:Order": "123456789"
      }
    }
  }
}

Javascript code:

var json = response;
var order = json.object.entry.content['m:properties']['d:Order']; // Attempting to retrieve Order details from the above response.

Error (for example, jsbin.com):

"TypeError: Cannot read property 'entry' of undefined
    at null.js:27:25
    at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924
    at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866"

According to JSLint, the JSON response is valid.

json.object.entry appears to be incorrect ... however

Q: What is the correct syntax in Javascript to access the value of "order" (referred to as d:Order), particularly when both m:properties and d:Order contain colons in their names?

PS: I have suggested Vijay's original enquiry for reopening ... although chances seem slim. Hence, my new question.

Answer №1

To successfully extract the data, you must properly parse the JSON object. Keep in mind that there is no reference to an object property; instead, it should be json.entry.content.

response = `{
  "entry": {
    "@xml:base": "https://API_PROC_SRV/",
    "@xmlns": "http://www.w3.org/2005/Atom",
    "@xmlns:m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
    "@xmlns:d": "http://schemas.microsoft.com/ado/2007/08/dataservices",
    "id": "https://API_PROC_SRV/A_Order",
    "title": {
      "@type": "text",
      "#text": "A_Order()"
    },
    "updated": "2020-02-29T07:33:28Z",
    "category": {
      "@term": "Type",
      "@scheme": "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
    },
    "link": [],
    "content": {
      "@type": "application/xml",
      "m:properties": {
        "d:Order": "123456789"
      }
    }
  }
}`;
var json = JSON.parse(response);
var order = json.entry.content['m:properties']['d:Order'];
console.log(order);

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

Focusing solely on the data table by performing a lookup using the keyword "list"

Looking to extract specific ranking numbers from certain districts listed in the json data. I'm having trouble with the syntax, can anyone provide assistance? Here is a snippet of the code: staedte_id= list("02000", "09162", "05315", "06412", "08111", ...

I am wondering if it is feasible for a POST route to invoke another POST route and retrieve the response ('res') from the second POST in Express using Node.js

Currently, I have a POST route that triggers a function: router.route('/generateSeed').post(function(req,res){ generate_seed(res) }); UPDATE: Here is the genrate_seed() function function generate_seed(res) { var new_seed = lightwallet. ...

Capture and set the new value of the Datetime picker in MUI upon user's acceptance click

import React from 'react' import { Stack, Typography } from '@mui/material' import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker' import { renderTimeViewClock } from '@mui/x-date-pickers/timeViewRenderers&ap ...

Using jQuery to retrieve a file that has been uploaded through an input field with the type of 'file'

I am looking to extract the file that has been uploaded using an <input type='file'> tag. Currently, when I use $('#inputId').val(), it only retrieves the name of the file, not the actual content of the file itself. I came acros ...

Ensure password confirmation is correct

Currently, I'm utilizing Yup for form validation. You can check it out here: https://www.npmjs.com/package/yup. Additionally, I came across this package called yup-password which seemed helpful for validating my Formik forms. Here's the link to i ...

Receive a warning in the Heroku log stating "(node) sys is outdated. Util should be used instead" while the script is executed

I recently deployed a Node script on Heroku to be executed by a scheduler. However, upon running the script, I noticed a warning message in the logs. Dec 07 11:01:10 xxx heroku/scheduler.3255 Starting process with command `node bin/script` Dec 07 11:01:1 ...

Having trouble with the "initSdk" property being undefined in your React Native Appsflyer integration?

I'm currently facing an issue while trying to integrate AppsFlyer into a react native application. The error I am encountering is "Cannot read property 'initSdk' of undefined" Initially, I imported the react-native-appsflyer module as shown ...

The localStorage is currently being updated, however there seems to be an issue with the output where false is being mistakenly interpreted

My goal is to show the <BR/> component when the value is true, otherwise display the <Nothing/> component. Despite the value being false, the <BR/> is still appearing for some unknown reason. PC.js code: import React,{useContext, useStat ...

Debugging the Force-Directed D3 Graph

I stumbled upon a fantastic article that provided a detailed guide on creating a beautiful D3 force layout graph. However, I'm facing some difficulties with the JSON source: The "links" attribute in the author's JSON doesn't seem clear to m ...

Uploading information to a server using Angular.js

I am currently working on developing an application with the following code snippet: function attendeeCtrl($scope, $http) { $scope.submit = function () { console.log($scope.noattendees); $http({ method: 'POST', ...

Managing traffic in Google Kubernetes Engine (GKE)

I am encountering an issue with our website deployment on GKE, which consists of 10 pods. When deploying a new version, we use MAXsurge=1 and MAXunavailable=0. Upon trying to access the website during a new deployment, I sometimes only see the header in t ...

Multi-line input in ExtJs

Is there a way to create a multiline input with vertical scrollbars in EXTJS? I tried the following code: noteField = new Ext.form.TextField({ emptyText: 'note...', multiline: true, applyTo: &apos ...

Is there a delay in Javascript identifying user existence when retrieving values from ajax?

I'm working on a script that checks if a username already exists before allowing a visitor to proceed. Here's a snippet of the code I'm using: EDIT: I've made some adjustments based on your feedback, but I'm still having trouble g ...

Having trouble with the Keydown event - the image isn't moving as expected

Something seems off with my code. I have an image displayed on a canvas, but when I press the specified key, nothing happens. Can you help me figure out where I went wrong? let img = document.getElementById("ship"); let player = { x: 375, ...

Dealing with errors effectively in AngularJS $http requests

What is the best approach for handling connection errors in Angular? When using the $http POST service: dossierService.getDossier(uid) .then(function (result) { vm.dossier = result.dossier; }, function (error) { handleErro ...

Is it possible to import files in Vue JavaScript?

I want to incorporate mathematical symbols from strings extracted from a JSON file. While it seems to work perfectly on this example, unfortunately, I encountered an issue when trying it on my own machine. The error message 'Uncaught (in promise) Refe ...

Properly handling the use of single and double quotation marks in variable declarations within a JavaScript file

I have a search box where users can enter their search text. For example, they can type book, 'book', or "book". The value entered in the search box is then assigned to a variable in the JavaScript file. var searchTerm = "${searchTerm}"; <br/ ...

Store information in Factory and retrieve it in the controller

I am encountering an issue with my code. Below is the factory code: .factory('shareDataService', function() { var sharedData = {}; sharedData.shareData = function(dateFrom, dateTo) { var from = dateFrom; var to = dateTo ...

Language for describing JSON data structures

Imagine my application needing to access data from multiple REST APIs, each supporting JSON responses but varying in the fields used to describe the data. For instance, one API may use time, while another may use timestamp for timestamp data, and similar v ...

What could be causing my array to update when the method is called live but not during unit tests?

One of my methods is called toggleSelect which adds and removes items from an array named selectedItems. This method functions perfectly when I test it live in the browser. However, when running unit tests, it does not seem to work as expected. Despite cal ...