I have this following json nested structure that i need to construct in pentaho:
{
"num_matricula": "4242424",
"limit_date": "2018-01-01",
"admission_date": "2018-01-01",
"cost_center": "anywhere",
"pos_number": "pos-test",
"role": "b63e065f-d7e0-49e1-91b7-88f74516e3fe",
"department": "bf559996-a8b9-4f5e-af57-86111b0dbde3",
"pagamento": {
"vinculo": "clt",
"valor": "4200",
"recorrencia": "mensalista",
"contaBancaria": {
"banco": "001",
"carta": "c9160763-db6c-4e8c-a1ad-ad8709c99be2"
}
},
"deficiencia": false,
"jornada": "De segunda a sexta das 15 as 19",
"profile": {
"name": "John Doe",
"email": "john.doe#acessodigital.com.br",
"mobile": "11911111111"
},
"exame": {
"clinica": "6dc84ce4-7d9f-48ec-b9b1-a8a895a21fd4",
"data": "2018-01-01",
"hora": "14:00",
"obs": "Comparecer de manhã",
"guia": "e37dab24-c7a4-4b92-b9d1-32ed538b8300",
},
"docs": ["c9e26093-5e0c-4bd2-bea3-ac5182a6179f"],
"send_sms": true,
"send_email": true
}
All the values come from the step "Select Values" which one gather the columns and the values to construct the json structure how it is showed in the following screenshot:
I've seen some solutions about using JavaScript to construct nested json structure in Pentaho, but i was not so sure about to create this using values from other steps. Can someone help me to construct this in pentaho? Pleasee.
Related
How would access the _id and state values?
Here's the data
{
"data": {
"totalSamplesTested": "578841",
"totalConfirmedCases": 61307,
"totalActiveCases": 3627,
"discharged": 56557,
"death": 1123,
"states": [
{
"state": "Lagos",
"_id": "O3F8Nr2qg",
"confirmedCases": 20555,
"casesOnAdmission": 934,
"discharged": 19414,
"death": 207
},
{
"state": "FCT",
"_id": "QFlGp4md3y",
"confirmedCases": 5910,
"casesOnAdmission": 542,
"discharged": 5289,
"death": 79
}
]
}
}
What you have shown is a string in JSON format. You can convert that to a JavaScript object and then start to get the values you need from it.
let str = ‘{
"data": {
"totalSamplesTested": "578841",
"totalConfirmedCases": 61307,
"totalActiveCases": 3627,
"discharged": 56557,
"death": 1123,
"states": [
{
"state": "Lagos",
"_id": "O3F8Nr2qg",
"confirmedCases": 20555,
"casesOnAdmission": 934,
"discharged": 19414,
"death": 207
},
{
"state": "FCT",
"_id": "QFlGp4md3y",
"confirmedCases": 5910,
"casesOnAdmission": 542,
"discharged": 5289,
"death": 79
}
]
}
} ‘;
(Note, I have put the string in single quotes so it can be shown properly here but in your code you need to put it in back ticks so it can span many lines)
Now convert it to a JavaScript object.
let obj = JSON.parse(str);
Now look closely at the string to see how the object is structured. It actually has just one item in it, data. And that is itself an object with several items, one of which is states which is an array.
So, obj.data.states[0] is the array’s first entry. That is an object and has _id and state items.
You can step through the array extracting the ._id and .state entries.
I have two variables with two different array objects. One is the collection(this.collection) object and the second is the user(this.user) object.
I want to join this two objects into one by the UID.
Here is the collection object:
{
"id":"d67de5QJ",
"admins":[
"494949393"
],
"color":"#029ae4",
"components":{
"forums":false,
"pages":true,
"photos":false,
"videos":false
},
"createdAt":"2018-02-09 14:38:59",
"description":"Angular is a TypeS",
"homepage":"pages",
"photoURL":"https://firebase..",
"status":"Public",
"title":"Angular 5",
"uid":"hlyAbEUfJhbxy",
"updatedAt":"2018-02-09 14:38:59"
}
And here is the user object
{
"bio": "<strong>PROFILE NEEDS EDITING",
"contactInfo": {
...
},
"createdAt": "2018-02-09 12:43:47",
,
"email": "email#gmail.com",
"avatar": "https://lh5.googleusercontent.com/-3LjYEmTIZlo/A...",
"roles": {
"admin": false,
"dealer": false,
"user": true
},
"status": "online",
"uid": "hlyAbEUfJhbxy",
"updatedAt": "2018-02-09 14:37:23",
}
How can I achieve this with LoDash or vanilla JavaScript? As you can see, there are other common properties like updatedAt and createdAd.
I tried this but I get an empty object
if(this.collection) {
this._auth.getUser(this.collection.uid).subscribe((user) => {
this.user = user;
const col = unionBy(this.user, this.collection, this.collection.uid)
console.log(col)
});
Object.assign() would work for this. Here you can find detail explanation.
See fiddle here
var col = {
"id":"d67de5QJ",
"admins":[
"494949393"
],
"color":"#029ae4",
"components":{
"forums":false,
"pages":true,
"photos":false,
"videos":false
},
"createdAt":"2018-02-09 14:38:59",
"description":"Angular is a TypeS",
"homepage":"pages",
"photoURL":"https://firebase..",
"status":"Public",
"title":"Angular 5",
"uid":"hlyAbEUfJhbxy",
"updatedAt":"2018-02-09 14:38:59"
}
var user = {
"bio": "<strong>PROFILE NEEDS EDITING",
"createdAt": "2018-02-09 12:43:47",
"email": "email#gmail.com",
"avatar": "https://lh5.googleusercontent.com/-3LjYEmTIZlo/A...",
"roles": {
"admin": false,
"dealer": false,
"user": true
},
"status": "online",
"uid": "hlyAbEUfJhbxy",
"updatedAt": "2018-02-09 14:37:23",
}
console.log(Object.assign(col,user))
You can use loadash merge : _.merge. unlike Object.assign, _.merge even handles nested objects. Find the documentation and example here.
Thank you for the help in advance. I am using a plugin which is expecting a JSON response to be an array not a object. Below is a sample of the JSON response I am getting
{
"instruments": [
{
"id": 3316,
"code": "WES",
"market_code": "ASX",
"name": "Wesfarmers Limited",
"currency_code": "AUD",
"pe_ratio": 16.38,
"nta": 4.44,
"eps": 2.55,
"current_price": 41.78,
"current_price_updated_at": "2017-10-26T16:10:09.000+11:00",
"sector_classification_name": "Retail Trade",
"industry_classification_name": "Food Retail",
"security_type": "Ordinary Shares",
"registry_name": "Computershare"
},
{
"id": 2955,
"code": "RIO",
"market_code": "ASX",
"name": "Rio Tinto Limited",
"currency_code": "AUD",
"pe_ratio": 14.95,
"nta": 27.77,
"eps": 4.66,
"current_price": 69.66,
"current_price_updated_at": "2017-10-26T16:10:11.000+11:00",
"sector_classification_name": "Non-Energy Minerals",
"industry_classification_name": "Other Metals/Minerals",
"security_type": "Ordinary Shares",
"registry_name": "Computershare"
},
],
"links": {}
}
The array I need to pull out into its own JSON object is the instruments array.
Now typically I know I would access that data via (if the response variable was called data) data.instruments[0].name as a example which would give me Wesfarmers limited
but if I want that entire array to sit in a new variable, which can then be parsed, how can I get that to happen?
Cheers
arr=new Array(data.instruments)
From Facebook's API I get an Array of 25 JSON objects back that I want to save to my Mongo database, how do I accomplish that using NodeJS, MongoDB/mongoose, superagent/request?
Do I iterate over the array of objects or how would I do it?
This is how each Object looks like:
{
"message": "I phone 5s 16 gb\nkr.1,000 - Vejen, Ribe, Denmark\n\n16 gb space grey .Ingenfejl i skærmen og original.\nCa.2,5 gammel .Telefonen virker perfekt.\nUbetydelig lille bule i bagside.\n\nBYD BYD BYD",
"from": {
"name": "Yalnız Kurt",
"id": "10212529378940059"
},
"name": "Photos from Yalnız Kurt's post",
"permalink_url": "https://www.facebook.com/groups/306677009409252/permalink/1332619516814991/?sale_post_id=1332619516814991",
"type": "photo",
"created_time": "2017-04-24T14:29:15+0000",
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-0/s130x130/18118670_10212529315698478_3112710548797328966_n.jpg?oh=b730b6621f2b50e43d3a646ce79b98ff&oe=5974B1DE",
"id": "306677009409252_1332619516814991"
}
Previously I was using a json file with the following format:
[{"lat":43.788458853157117,"lng":-79.282781549043008,"category":"volunteer","name":"Rita","url":"", "description":"xxx is a member of 13"},{"lat":43.7,"lng":-79.4,"category":"organization","name":"TCAN","url":"http://tcan.ca","description":"Lorem ipsum"}]
Now I am attempting to generate the json file from a Drupal site and am getting the following structure. How can I reference the lowest level fields. I have looked at examples using d3.net but have not found any that apply.
{
"organizations": [
{
"member": {
"field_category": "organization",
"body": "A network of organizations in Toronto devoted to climate change mitigation and adaptation.",
"URL": "xxx.ca",
"title": "Toronto Climate Action Network",
"field_lat": 43.7,
"field_long": -79.4
}
},
{
"member": {
"field_category": "abc",
"body": "xxx.",
"URL": "",
"title": "yyy",
"field_lat": 43.7,
"field_long": -79.28
}
}
]
}
Assuming that your data is stored in the variable data:
var bottom = data.organizations.map(function(d) { return d.member; });