AnsweredAssumed Answered

Pentaho javascript code variable object

Question asked by Manuel b munoz on Aug 15, 2018
Latest reply on Aug 20, 2018 by Ricardo Diaz

I am trying to navigate my object with the response of my rest client method, this response is theoretically a JSON Object such that.

{"457": {"2": {"value": "53.8", "timestamp": 1534257707}, "3": {"value": "21.9", "timestamp": 1534257707}, "4": {"value": "255.0", "timestamp": 1534257707}, "21": {"value": "996.0", "timestamp": 1534257707}, "1": {"value": "4.15", " timestamp ": 1534257707}," 17 ": {" value ":" 156.99062499999997 "," timestamp ": 1534257707}," 5 ": {" value ":" 37.667 "," timestamp ": 1534257707}," 6 ": {"value": "28.900000000000002", "timestamp": 1534257707}, "8": {"value": "4.28", "timestamp": 1534257707}, "15": {"value": "0.83", " timestamp ": 1534257707}," 10 ": {" value ":" 19.31 "," timestamp ": 1534257707}," 22 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 23 ": {"value": "0.0", "timestamp": 1534257707}, "24": {"value": "0.0", "timestamp": 1534257707}, "26": {"value": "0.0", " timestamp ": 1534257707}," 653 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 657 ": {" value ":" - 98.0 "," timestamp ": 1518420299}," 43 " : {"value": "11.824136243472958", "timestamp": 1534257707}, "42": {"value": "326.54049999999995", "timestamp": 1534257707}}} 

I have created a component in JavaScript to process this data:

This is my code in java script and it works correctly, since I have tried it programming it in another environment.

var key = Object.keys (data) [0]; var finalobj = {};     for (var and in data [key]) {     finalobj [e] = {     type: "float"     , value: parseFloat (data [key] [e] .value)     , metadata: {     timestamp: {     value: parseInt (data [key] [e] .timestamp)     , type: "Integer"     }     }     };     } 

The problem is that if I assign to the field it dates the value of my answer like this:

var data = result_ult_dat; 

When I throw the code it does not work, but if I manually assign the code to it, if it works correctly, what is the problem ?, I do not understand it, the value of result_ult_dat is the same as the one that I copied, it has to be transforming or something like this:

var data = {"457": {"2": {"value": "53.8", "timestamp": 1534257707}, "3": {"value": "21.9", "timestamp": 1534257707}, " 4 ": {" value ":" 255.0 "," timestamp ": 1534257707}," 21 ": {" value ":" 996.0 "," timestamp ": 1534257707}," 1 ": {" value ":" 4.15 "," timestamp ": 1534257707}," 17 ": {" value ":" 156.99062499999997 "," timestamp ": 1534257707}," 5 ": {" value ":" 37.667 "," timestamp ": 1534257707}," 6 ": {" value ":" 28.900000000000002 "," timestamp ": 1534257707}," 8 ": {" value ":" 4.28 "," timestamp ": 1534257707}," 15 ": {" value ":" 0.83 "," timestamp ": 1534257707}," 10 ": {" value ":" 19.31 "," timestamp ": 1534257707}," 22 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 23 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 24 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 26 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 653 ": {" value ":" 0.0 "," timestamp ": 1534257707}," 657 ": {" value ":" - 98.0 "," timestamp ": 1518420299}, "43": {"value": "11.824136243472958", "timestamp": 1534257707}, "42": {"value": "326.54049999999995", "timestamp": 1534257707}}}; 

How can I fix the problem.

Outcomes