Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
How do you extract data from a javascript object when you don’t know the name of the property field because it was is a hashmap object in java?

How do you extract specific data from a javascript object when you don’t know the name of the property field because it is an object that was converted from a hashmap in java?

In my case, I created a Hashmap object in java and using the put method, I put into this object three key/value pairs. This hashmap object is a part of another java model object which just has ordinary fields namely: name (String) and id number(int). I then converted the output of a method that has an object, which includes the two fields and the hashmap object, into a json object to be used in javascript.

The problem is that I can access the name and id fields in javascript by using the dot accessor I.e. obj.name and obj.id but I don’t know how to access the information from the hashmap separately which was converted to json because the key/values don’t have named fields.

When I use the the dot accessor and put in the name of the hashmap object (in other words obj.student where ‘student’ is the name of the hashmap) it gives me both the key and values i.e name of student “Paul” and grade ‘9’ (the hasmap has String for names and int for grades).

What I’d like is to be able to access both key and values separately as I want to use then in a chart js chart.

for (var i=0; i<jsonString.length; i++) {

    let obj = jsonString[i];

    xValues[i] = obj.name;

    yValues[i] = obj.id;

    const myJSON = JSON.stringify(obj.student);
   
 xValuesOne[i] = myJSON;
}

The above code works for extracting the name and id properties but for the student property, as it was a hashmap in java, the specific values don’t have names that I can use to extract the properties.

The string part should be the students name (x-axis) and the int part of the hashmap should be their grade (y-axis).

At the moment in relation to the student data, xValuesOne[i] produces both the string (name) and int (grade) in the x-axis. I would like to extract both the string and the int separately and place them in different axis for chart js.

Any ideas on how to do this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!