How to access value of a JSON object whose key is value of another JSON object?

how to get key and value from json array object in javascript
get value from json object in javascript
get value from nested json object in javascript
get key value from json object in java
how to access json array in javascript
iterate through json object java
convert string to json
javascript object

I'm new to javascript. I have a strange requirement.

How can we access the value of an object whose key is the value of another object?

Ex:

Obj1 = {"name":"John", "age":30, "car":null};
Obj2 = {"John":{"country":"america", "job":"Engineer"}}

How to achieve something like Obj2.{Obj1.name}.country (result: america)

Just use bracket notation like so:

Obj1 = {"name":"John", "age":30, "car":null};
Obj2 = {"John":{"country":"america", "job":"Engineer"}}

Obj2[Obj1.name].country;
// or
Obj2[Obj1["name"]]["country"]

JSON Objects, Im new to javascript I have a strange requirementHow can we access the value of an object whose key is the value of another objectExObj1 .do(data => console.log(“All: ” + JSON.stringify(data))).catch(this.handleError);} I need to parse JSON response in key value pair. Please note channel list– contain hashmap of channel name and its description so key value will differ on calls from one client to another client. Keys will also not remain same as there are different channels.

You can access object properties using the square bracket syntax.

object.property is equal to object["property"].

For your example, you can do

console.log(Obj2[Obj1.name]);

Object initializer, JSON permits only property definition using "property": value syntax. The values of these keys are a string "bar" , the number 42 , and another object. function ( parameters ) {}, get property () {}, set property ( value ) {} } there is a way to concisely define properties whose values are generator functions: data = json.loads('{"lat":444, "lon":555}') ret = '' for j in data: ret = ret+" "+data[j] return ret When you use for in this manor you get the key of the object, not the value, so you can get the value, by using the key as an index.

You can try the following Obj2[Obj1['name']]['country']

Read values from json object using keys, Hi, I have a requirement where in i need to parse a json object without knowing the keys i get in the payload. I found a way to get the keys using� Access and print a specific JSON value This tutorial continues from the previous topic, Inspect the JSON from the response payload . In the sample page where you logged the weather response to the JS Console, the REST response information didn’t appear on the page.

Reshaping JSON with jq, In brief, a JSON object is a series of key/value pairs, where keys are the If you want to access a value in an object that's already within another object, For example, let's select only those objects whose primary maker has� Object.keys(obj[2].type) doesn't really make sense here. You're not iterating over the properties of any object, you're accessing the same property in a set of objects. This is what map does. var types = obj.types.map(x => x.type);

JsonObject (Java(TM) EE 7 Specification APIs), JsonObject class represents an immutable JSON object value (an unordered collection of This map object provides read-only access to the JSON object data, and Parameters: name - the name whose associated value is to be returned� var domainObject = responseObject.json(); This converts the response object into a js object. I can then easily access a property on this object like this. var users = domainObject.Users Users is a collection of key/value pairs like this: 1: "Bob Smith" 2: "Jane Doe" 3: "Bill Jones" But CDT shows users as Object type and users[0] returns undefined.

JSONObject, The values can be any of these types: Boolean , JSONArray , JSONObject , Number , String , or the JSONObject. JSON text into an internal form whose values can be retrieved with the get Get the JSONObject value associated with a key. Just convert the JSON string to an object using JSON.parse() and then add the property. If you need it back into a string, do JSON.stringify(). BTW, there's no such thing as a JSON object. There are objects, and there are JSON strings that represent those objects.