I'm having trouble getting to object in json file.
I'm using
.controller("ListController", ["$scope", "$http", function($scope, $http){
$http.get('../scripts/bbtv.json').success(function(data) {
$scope.artists = data;
});
}])
The data gets in the variable, but I can't access any object of it. Here is part of the json file. For example how to print out {{programmeField.titleField.valueField}} ?
{
"channelField": [
{
"displaynameField": [
{
"valueField": "bTV"
}
],
"idField": "BBTV"
}
],
"programmeField": [
{
"titleField": [
{
"langField": "BULG",
"valueField": "Тази сутрин"
}
],
"subtitleField": [],
"creditsField": {
"moderatorField": [
"Антон Хекимян"
]
},
"categoryField": [
{
"langField": "BULG",
"valueField": "Информационно предаване"
},
{
"langField": "BULG",
"valueField": "Сутрешен блок"
}
],
"languageField": {
"valueField": "BULG"
},
"lengthField": {
"unitsField": 1,
"valueField": "180"
},
"videoField": {
"presentField": "yes",
"colourField": "yes",
"aspectField": "4:3",
"qualityField": "800x600"
},
"audioField": {
"presentField": "yes",
"stereoField": "no",
"dolbyDigitalField": "no",
"dolbySurroundField": "no"
},
"startField": "20151216063000 +0200",
"stopField": "20151216093000 +0200",
"channelField": "BBTV",
"clumpidxField": "0/1",
"_photos": [
{
"_id": "5f38a2ab2fedd6b0e48da60b833bb4ddb69d3a1c",
"_url": "***.jpg",
"_type": "Letterbox"
}
],
"_deleted": false,
"_id": "189397717",
"_contentId": 45207610,
"_broadcastdate": "20151216"
}
}
JSON is a transport format. Once it's decoded, it's a native data structure, like any other structure. Since you're in JS, use JS conventions, and follow the bracketing/bracing. Note the labelling on the objects/arrays below:
data = { "channelField": [
a b
{ "displaynameField": [
c d
{ "valueField": "bTV"
e
}
],
"idField": "BBTV"
data.channelField[0].displaynameField[0].valueField -> "bTV"
a b c d e
Since your "programmeField" and "titleField" are array, use programmeField[0].titleField[0].valueField
In future you can copy your json to http://jsonviewer.stack.hu/ and the click on the Viewer tab.
Related
Have the sandbox with working React forms array
https://codesandbox.io/s/react-final-form-field-arrays-react-beatiful-dnd-as-drag-drop-forked-uz24z?file=/index.js:5933-6061
Which in result of click on the add hotspots and generate the data tree as
{
"toppings":[
],
"customers":[
{
"id":4,
"firstName":"name",
"lastName":"lastname"
},
{
"id":5,
"firstName":"Clark",
"lastName":"kent"
}
],
"hotspots":[
{
"hotspotId":6,
"positionY":"Xhostspotforcustomer1",
"positionX":"Yhostspotforcustomer1"
}
]
}
But I need hotspots to be added as children of customer when click on the Add Hotspot button (to same index of the values.customers array) like
{
"toppings":[
],
"customers":[
{
"id":4,
"firstName":"name",
"lastName":"lastname",
"hotspots":[
{
"hotspotId":6,
"positionY":"XhostspotforcustomerID4",
"positionX":"YhostspotforcustomerID4"
},
{
"hotspotId":7,
"positionY":"more XhostspotforcustomerID4",
"positionX":"new YhostspotforcustomerID4"
}
]
},
{
"id":5,
"firstName":"Clark",
"lastName":"kent",
"hotspots":[
{
"hotspotId":8,
"positionY":"XhostspotforcustomerID5",
"positionX":"YhostspotforcustomerID5"
}
]
}
],
}
The Add hotspot is added on line 174 of index.js
How to modify the code to add hotspots per customer separately ?
you need to combine customer field name with hotspot name:
when you do push/pop:
push(`${name}.hotspots`, /*...*/)
//...
pop(`${name}.hotspots`)
also in FieldArray field name:
<FieldArray name={`${name}.hotspots`}>
Demo: https://codesandbox.io/s/react-final-form-field-arrays-react-beatiful-dnd-as-drag-drop-forked-wivwu?file=/index.js
Result:
{
"toppings": [],
"customers": [
{
"id": 4,
"firstName": "name",
"lastName": "lastname",
"hotspots": [
{
"hotspotId": 6,
"positionY": "Customer4-Y1",
"positionX": "Customer4-X1"
},
{
"hotspotId": 7,
"positionY": "Customer4-Y2",
"positionX": "Customer4-X2"
}
]
},
{
"id": 5,
"firstName": "Clark",
"lastName": "kent",
"hotspots": [
{
"hotspotId": 8,
"positionY": "Customer5-Y1",
"positionX": "Customer5-X1"
}
]
}
]
}
I have two JSON data sources:
Source Data 1:
{
"result": [
{
"resource_list": "7961b907db9253045fbdf1fabf9619d4,55617907db9253045fbdf1fabf9619d2",
"project": "11216",
"project_manager": {
"value": "55617907db9253045fbdf1fabf9619d2"
}
}
]
}
Source Data 2:
{
"result": [
{
"sys_id": "7961b907db9253045fbdf1fabf9619d4",
"email": "test.user1#mysite.com"
},
{
"sys_id": "55617907db9253045fbdf1fabf9619d2",
"email": "test.user2#mysite.com"
}
]
}
I want to reference "resource_list" and "project_manager" from Source Data 1 to "sys_id" in Source Data 2 and get "email" out from Source Data 2 and then compose a final Output like below:
Output:
[
{
"__metadata":
{
"uri": "ProjectCode"
},
"externalProject": "11216",
"projectCodeAssignment":
[
{
"__metadata":
{
"uri": "projectCodeAssignment"
},
"externalProjectAssignee": "test.user1#mysite.com"
},
{
"__metadata":
{
"uri": "projectCodeAssignment"
},
"externalProjectAssignee": "test.user2#mysite.com"
}
]
}
]
Is this possible to get this done entirely in Logic App without using Function App or anything to perform it rather.
I write a js script for you. For a quick demo, I omitted some data related to __metadata, seems that is some hard code, not so important here. Try Logic below:
Code in JS code action:
var body = workflowContext.trigger.outputs.body
var data1 = body.data1;
var data2 = body.data2;
var result = [];
data1.result.forEach(item =>{
var resultItem = {};
resultItem.externalProject = item.project;
resultItem.projectCodeAssignment =[];
var resourceIds = item.resource_list.split(',');
resourceIds.forEach(id =>{
var user = data2.result.find( ({ sys_id }) => sys_id === id );
resultItem.projectCodeAssignment.push({"externalProjectAssignee": user.email})
});
result.push(resultItem);
})
return result;
Request Body(your 2 data set are named as data1 and data2 here ):
{
"data1": {
"result": [{
"resource_list": "7961b907db9253045fbdf1fabf9619d4,55617907db9253045fbdf1fabf9619d2",
"project": "11216",
"project_manager": {
"value": "55617907db9253045fbdf1fabf9619d2"
}
}
]
},
"data2": {
"result": [{
"sys_id": "7961b907db9253045fbdf1fabf9619d4",
"email": "test.user1#mysite.com"
}, {
"sys_id": "55617907db9253045fbdf1fabf9619d2",
"email": "test.user2#mysite.com"
}
]
}
}
Result:
I want to upload all of my form data to google sheet. I tried on it but still can't store data on google sheet.
Here my Gsheet Api Call
{
"requests": [
{
"repeatCell": {
"range": {
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 1,
"sheetId": 0
},
"cell": {
"userEnteredValue": {
"stringValue": "Adnan1",
"stringValue": "Adnan2",
"stringValue": "Adnan3",
"stringValue": "Adnan4"
}
},
"fields": "*"
}
}
]
}
Using this i update only one cell i know it's due to dimension but is there any way to store all of my form data to gsheet. Thank You
You're using RepeatCellRequest which is intended to repeat the same value in the selected range of cells. You could use a UpdateCellsRequest and use the rows field to set the values. The below example sets 3 rows values to the first column:
{
"requests": [
{
"updateCells": {
"range": {
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 3,
"sheetId": 0
},
"rows": [
{
"values": [
{
"userEnteredValue": {
"stringValue": "Adnan1"
}
}
]
},
{
"values": [
{
"userEnteredValue": {
"stringValue": "Adnan2"
}
}
]
},
{
"values": [
{
"userEnteredValue": {
"stringValue": "Adnan3"
}
}
]
}
],
"fields": "*"
}
}
]
}
I am trying to query documents from a mongodb collection, based on array of input query parameters sent from URL.
Sample Database Data
[
{
"drawings": {
"circle": [],
"square": [
{
"id": "828",
"name": "square"
}
],
"cube": []
},
{
"drawings": {
"circle": [
{
"id": "827",
"name": "circle"
}
],
"square": [],
"cube": []
},
{
"drawings": {
"circle": [],
"square": [],
"cube": [
{
"id": "829",
"name": "cube"
}
]
}
]
Input Query Parameter:
query = ["square","cube"];
Expected Output:
[
{
"drawings": {
"circle": [],
"square": [
{
"id": "828",
"name": "square"
}
],
"cube": []
},
{
"drawings": {
"circle": [],
"square": [],
"cube": [
{
"id": "829",
"name": "cube"
}
]
}
]
Best suited Mongoose Query:
Schema.find({
$or:[
{'drawings.square':{$elemMatch:{ name:'square'}}},
{'drawings.cube':{$elemMatch:{ name:'cube'}}}
]
});
Tried Below method. But, it is not correct.
let draw = ["square","cube"];
let draw_query =[];
for (let a=0; a<draw.length;a++){
draw_query.push("{\"drawings."+ draw[a] +"\':{$elemMatch:{ name:\"" + draw[a] + "\"}}}");
}
It creates array with single quoted strings. It cannot be used.
[ '{"drawings.square":{$elemMatch:{ name:"square"}}}',
'{"drawings.cube":{$elemMatch:{ name:"cube"}}}' ]
How to generate this mongoose query dynamically? or is there any better mongoose query to achieve the expected result.
You can query it directly using dot notation so the query should look like below:
db.collection.find({
$or: [
{
"drawings.square.name": "square"
},
{
"drawings.circle.name": "circle"
}
]
})
You can build it in JS using .map(), try:
var query = ["square","cube"];
var orQuery = { $or: query.map(x => ({ [x + ".name"]: x }) ) }
I have a question on Updating the array in RethinkDB. My JSON structure looks like below.
{
"LOG_EVENT": {
"ATTRIBUTES": [
{
"ATTRIBUTE1": "TYPE",
"VALUE": "ORDER"
},
{
"ATTRIBUTE2": "NUMBER",
"VALUE": "1234567"
}
],
"EVENT_CODE": [
{
"CODE_NAME": "EVENT_SAVED",
"EVENT_TIMESTAMP": "2015-08-18T00:58:12.421+08:00"
}
],
"MSG_HEADER": {
"BUSINESS_OBJ_TYPE": "order",
"MSG_ID": "f79a672b-f15e-459d-a29b-725486d6401f",
"DESTINATIONS": "3"
}
},
"id": "0de3117e-12dd-4d10-a464-dff391a4513f"
}
Here, I am trying to Update a new event inside my event code
{
"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2",
"EVENT_TIMESTAMP": "2015-08-18T12:58:12.421+08:00"
}
My final JSON will look like below,
{
"LOG_EVENT": {
"ATTRIBUTES": [
{
"ATTRIBUTE1": "TYPE",
"VALUE": "ORDER"
},
{
"ATTRIBUTE2": "NUMBER",
"VALUE": "1234567"
}
],
"EVENT_CODE": [
{
"CODE_NAME": "EVENT_SAVED",
"EVENT_TIMESTAMP": "2015-08-18T00:58:12.421+08:00"
},
{
"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2",
"EVENT_TIMESTAMP": "2015-08-18T12:58:12.421+08:00"
}
],
"MSG_HEADER": {
"BUSINESS_OBJ_TYPE": "order",
"MSG_ID": "f79a672b-f15e-459d-a29b-725486d6401f",
"DESTINATIONS": "3"
}
},
"id": "0de3117e-12dd-4d10-a464-dff391a4513f"
}
Can you help on the ReQL query ?
Tried below, but not working
r.db("test").table("test1").get("0de3117e-12dd-4d10-a464-dff391a4513f")("LOG_EVENT")('EVENT_CODE').update(function(row) {
return {EVENT_CODE: row('EVENT_CODE').map(function(d) {
return r.branch(d.append({
"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2",
"EVENT_TIMESTAMP": "2015-08-18T00:58:12.421+08:00"
}), d)
})
}} )
well here is the code which updates the nested fields of object residing inside an array
r.db('DB').table('LOGS')
.get('ID')
.update({
EVENT_CODE: r.row('EVENT_CODE')
.changeAt(1, r.row('EVENT_CODE').nth(1)
.merge({"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2"}))
})