Access object key containing character : [duplicate] - javascript

This question already has an answer here:
Parsing a JSON object with Special characters in property key
(1 answer)
Closed 3 years ago.
I am pulling in reviews from iOS and the key they have has a : in the middle.
Like so: im:rating: {attributes: {…}}
Therefore, doing something like this is not working. {entry.im:rating.label}
How do I get the label from im:rating?

Simple answer: entry['im:rating'].label

Related

JSON object to Array Javascript [duplicate]

This question already has answers here:
How do I loop through or enumerate a JavaScript object?
(48 answers)
Closed 2 years ago.
Im seeing a lot of answers to this in simple arrays but I need the keys and value. I have a json object but need an array. The object looks like this:
{"Food":"Starbucks", "Job":"Electrician"}
I just need a simple array like this:
["Food" => "Starbucks", "Job" => "Electrician"]
Edit: Im not sure how to type it out. Just need to be able to do an array.map and get the keys and values in javascript.
Here is the final code that I am trying:
const details = jsonObject;
{details.map(function(item,idx){
return<DetailCell>
<Label>{idx}</Label>
<Text style={TextStyle}>{item}</Text>
</DetailCell>
})}
Label should be the key and the Text should be the value.
I think you need this :
[{"Food" : "Starbucks"}, {"Job" : "Electrician"}]
To declare a literal array value is something like this in JSON in node.
{JSONVarWithArrayValue : [0,0,0,0]}

How to escape # in javascript to retrive object property [duplicate]

This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(17 answers)
Closed 7 years ago.
i have Javascript object as below.
How can i get value for SERIAL#, like i can retrieve *.INST_ID or *.INSTANCE.
how can i escape # and get the value required.
So far i have tried SERIAL#23% but none helped so far.
var t = {"INST_ID":"1","INSTANCE":"xina","SID":"27","SERIAL#":"48810", "PROGRAM":"Perl#app01"}
console.log(kSess.SERIAL%23); gives syntax error
I am parsing variable "t"
This data is coming from java code, so there is nothing much i can do to change SERIAL# to something else
Any idea?
Try to retrieve the value like this...
t["SERIAL#"]; // will return you the value..
Store it somewhere or play with it as you like. :)

Reading Json slash in Javascript [duplicate]

This question already has answers here:
How can I access object properties containing special characters?
(2 answers)
Closed 7 years ago.
I'm reading a JSON file through javascript. I'm having trouble getting today/_text because of the forward slash. I can get today successfully by doing: {{hours.results[0].today}}. How would I get today/_text? I've tried:
today\/_text
today/\_text
today//_text
today\\/_text
{"offset":0,"results":[{"today/_text":"Today:YES","today/_source":"/hours/1","today":"2,3,4"}]}
hours.results[0]["today/_text"] should do the trick!
hours.results[0] returns an object that has that as a key, making that the easiest way to access the property in question.

Javascript Turn string into array [duplicate]

This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 7 years ago.
I want to turn this into an array
"["65747add-afd2-45b5-92e0-150bbe40e6d9", "9c247ea5-6b81-4f47-a50c-42367dedd50b", "c1555363-aca9-4e04-8844-e0180397c72e"]"
I am getting it from the page like this:
$('#layout-uuids').text()
Is there away to just get it as an array or do I need to turn the string into an array somehow?
Thanks!
That string looks like JSON. If it is indeed JSON, all you need is JSON.parse():
var someArray = JSON.parse($('#layout-uuids').text());

How do I display a JSON object in a pretty format , on my webpage? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JavaScript data formatting/pretty printer
var theobject_string = '{...}'; // I have a json object as a string.
How can I display this string in a pretty way, on my webpage (html)?
I want this the elements to be indented.
This library does exactly what you're looking for: http://www.cerny-online.com/cerny.js/demos/json-pretty-printing

Categories

Resources