I am trying to access a JSON field that has the key '*':
{
"parse": {
"text": {
"*": "text i want to access"
}
}
}
Neither myObject.parse.text.* nor myObject.parse.text[0] works.
I have searched for an hour but haven't found any hint that an asterisk has special meaning. If I just traverse the complete tree and make String comparison with if (key == "*") I can retrieve the text, but I would like to access this field directly. How can I do that?
Using wildcards in resource ARNs An asterisk (*) represents any combination of characters and a question mark (?) represents any single character.
In JSON the only characters you must escape are \, ", and control codes. Thus in order to escape your structure, you'll need a JSON specific function.
Insert JSON data into a table: To use an apostrophe or a single quotation mark (') in a value, add another single quotation mark after the first one.
json.parse.text["*"]
Yucky name for an object member.
Asterisks have no special meaning; it's a string like any other.
myObject.parse.text.* doesn't work because * isn't a legal JS identifier. Dot notation requires legal identifiers for each segment.
myObject.parse.text[0] doesn't work because [n] accesses the element keyed by n or an array element at index n. There is no array in the JSON, and there is nothing with a 0 key.
There is an element at the key '*', so json.parse.text['*'] works.
Try use the index operator on parse.text:
var value = object.parse.text["*"];
try to use
var text = myObject.parse.text['*']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With