How to get objects value if its name contains dots?
What you want is:
var smth = mydata.list[0]["points.bean.pointsBase"][0].time;
In JavaScript, any field you can access using the . operator, you can access using [] with a string version of the field name.
Parse value from JSON when key contains dot (period) in Powershell
If you put the property names in ""
or ''
, you should be able to get what you are looking for:
$json= @'
{ "id" : 9983,
"rev" : 17,
"fields" :{
"System.AreaPath":"Cloud\\Dev Blue Team",
"System.TeamProject":"Cloud"
}
}
'@
$j = $Json | convertfrom-json
$j.fields."System.AreaPath"
$J.fields.'System.TeamProject'
if you need to escape double quotes, use the `
grave accent, known as the backtick in PowerShell.
"area path = $($j.fields.`"System.AreaPath`")"
Get json object's value in php if its name contains dots in PHP
$obj->root->{'hello.world'}
will work.
ps: $obj->root->{hello.world}
might not work.
b.t.w: Why not use Array? json_decode($json, true)
will return Array. Then $a['root']['hello.world']
will always work.
Mapping a dot notation key in an object?
Since address.long_form
is in string, you cannot use dot notation instead use this
console.log(object['address.long_form'])
How to get the value of a property in javascript which has a dot in it's name?
You have to use the square bracket notation.
Config["pp.phaseName"]
dot character in property name
The purpose would be to store nested objects in a flat format, ie. a database table.
You could use something like dottie.js to transform this flat object into a nested object
const values = {
'user.name': 'Gummy Bear',
'user.email': 'gummybear@candymountain.com',
'user.professional.title': 'King',
'user.professional.employer': 'Candy Mountain'
};
const transformed = dottie.transform(values);
We would now find this to be the value of transformed
{
user: {
name: 'Gummy Bear',
email: 'gummybear@candymountain.com',
professional: {
title: 'King',
employer: 'Candy Mountain'
}
}
}
Why they use it like that in the example seems to be so that they can provide an example (below) on how to access these kinds of variable names. Imagine that you wanted the .toHaveProperty(keyPath value?)
function from the Jest docs to operate on a property in the values
object from the above example. This shows you how you might use this function with such a property.
// Referencing keys with dot in the key itself
expect(houseForSale).toHaveProperty(['ceiling.height'], 'tall');
Unless you have a very good reason, using these kinds of variable names is not a best practice and I would not recommend it. That said, while a variable name with a .
character is not able to be used with dot syntax:
houseForSale.ceiling.height = undefined
It is still accessible with bracket syntax:
houseForSale['ceiling.height'] = 2
Change object key names won't accept replacing dots
search
uses regular expressions (so .
matches any character!), just use string methods like indexOf
var obj = `{
"key1.key": "merciful",
"key2": {
"key2.key": "grateful"
},
"key3": {
"key3.keyA.keyB": "thankful"
}
}`
var parseDOT = JSON.parse(obj, function (k, v) {
let key = k;
if (key.indexOf(".") != -1){
while(key.indexOf(".") != -1)
key = key.replace(".","DOT");
this[key] = v;
}
else
return v;
});
console.log(parseDOT)
how to destruc an object which includes a long string with dot as the key
You can use computed properties, but you should provide the name like this const { ['journey.hintText.journeyTags']: journeyTags } = content
How to extract Json object value if object name contains period?
You can just do:
var subObject = jsonCC["com.app.connect.model.Login"];
Don't put a period between jsonCC
and [
Here is a JSFiddle of the working code.
Related Topics
Syntaxerror: Unexpected Token Function - Async Await Nodejs
What's the Difference Between Console.Dir and Console.Log
Ckeditor 4: Uncaught Typeerror: Cannot Read Property 'Langentries' of Null
Javascriptcore Call Function with Callback Swift
How to Run Node Js Code from Npm Inside of Swift
Jqgrid, How to Make a Column Editable in the Add Dialog But Not During (Inline) Edits
How to Set Header and Options in Axios
Using Enter Key with Action Button in R Shiny
How to Reduce JavaScript Object to Only Contain Properties from Interface
How to Detect Scroll Position of Page Using Jquery
Losing "This" Context in JavaScript When Passing Around Members
Youtube Iframe Player API - Onstatechange Not Firing