Column Values not Returned (GoogleSheets) - google-apps-script

Sheetlink
Column Values for Col_K(11) are returned as an EMPTY ARRAY however the previous column values Col_J(10) are returned fine.
Whats Missing?
CODE:
function oiNotif() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('OiNotif');
var condCol;
var triggerPrice;
condCol = sheet.getRange(2,10,sheet.getLastRow()).getValues();
triggerPrice = sheet.getRange(2,11,sheet.getLastRow()).getValues();
Logger.log(' condCol = %s',condCol);
Logger.log(' triggerPrice = %s',triggerPrice);
}
Log :
condCol = [[0.0], [0.0], [0.0], [true], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [true], [0.0], [0.0], [0.0], [true], [0.0], [0.0], [0.0], [true], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [0.0], [0.0], [0.0], [false], [false], [false], []]
triggerPrice = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]

Related

Perform complex jsonpath query

I have the following json response. I want to filter using json path as follows:
Get the first date for person ec7e231e-1fed-4860-a1ab-c2e3248a183e where 1. the date is not null and 2. the exam array is empty and 3. the absent flag is false
[
{
"Person": {
"ReferenceKey": "ec7e231e-1fed-4860-a1ab-c2e3248a183e",
"fname": "john",
"lname": "anderson",
"adress": null
},
"days": [
{
"date": null,
"absent": false,
"holiday": false,
"exam": [],
"blockingtimes": []
},
{
"date": "2021-02-19",
"absent": false,
"holiday": false,
"exam": [],
"blockingtimes": []
},
{
"date": "2021-02-20",
"absent": false,
"holiday": false,
"exam": [],
"blockingtimes": []
}
]
},
{
"Person": {
"ReferenceKey": "ec7e231e-1fed-4860-a1ab-c2e3248a1900",
"fname": "manny",
"lname": "panny",
"adress": null
},
"days": [
{
"date": null,
"absent": false,
"holiday": false,
"exam": [],
"blockingtimes": []
},
{
"date": "2021-02-19",
"absent": false,
"holiday": false,
"exam": [],
"blockingtimes": []
},
{
"date": "2021-02-20",
"absent": true,
"holiday": false,
"exam": [],
"blockingtimes": []
}
]
}
]
so far i was only able to retrieve all person uuids $..person.mitarbeiterReferenceKey
Something like
$.[?(#.Person.ReferenceKey == 'ec7e231e-1fed-4860-a1ab-c2e3248a183e')].days[?(#.date != null && #.absent == false && #.exam.length() == 0)])
More information:
Jayway JsonPath
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

How to parse nested JSON in snowflake and extracting a particular piece of information?

I am very new to snowflake and previously have worked in Teradata SQL. I am trying to retrieve information from a column in a snowflake table, whose values are in JSON and look like below:
{
"depositsDMPResponseVO": {
"depositsApplicationRsnsVO": {
"applicationID": "YYYYYYY",
"applicationRefNbr": "XXXXXXXXX",
"depositsStrategyOutputVOs": [
{
"appDescnTms": "2020-08-18T08:07:00Z",
"depositsAppDecisionVO": {
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
"depositsApplicantDescnVOs": [
{
"applicantDecisionsRuleVOs": [
{
"decision": "AP",
"decisionType": "CIP",
"finalDecision": false,
"reasonCodes": [],
"rule": true,
"ruleName": "DefaultCIP",
"strategyName": "DefaultCIP",
"weight": 100
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": true,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
{
"decision": "AP",
"decisionType": "CIP",
"finalDecision": false,
"reasonCodes": [],
"rule": false,
"ruleName": "DefaultCIP",
"strategyName": "DefaultCIP",
"weight": 100
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": true,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
}
],
"applicantModelScoreVOs": [
{
"modelId": "CHEX",
"reasonCd": [
"AX",
"AP",
"AD",
"AB",
null
],
"scoreNumber": "0576"
}
],
"applicantNbr": "DBAPPLCNT5920115",
"cipPrimVerifySrc": "LNIID",
"cipVerifyBy": "LexisNexis",
"cipVerifyMode": "NDOC",
"strDrvdAttr01": "isMktSrcHghRsk : 1",
"strDrvdAttr02": "totRskVal : 11",
"strDrvdAttr03": "isBnkCust : 0",
"strDrvdAttr04": "bnkCustTen : 0",
"strDrvdAttr05": "hasChkPrdct : 1",
"strDrvdAttr06": "isCrdCust : 0",
"strDrvdAttr07": "newTMXRskVal : 5",
"strDrvdAttr08": "TMXRskVal : 4",
"strDrvdAttr09": "newLNFPRskVal : 2",
"strDrvdAttr10": "LNFPRskVal : 1",
"strDrvdAttr11": "newEMAGRskVal : 4",
"strDrvdAttr12": "EMAGRskVal : 4",
"strDrvdAttr13": "tenureRskVal : 3",
"strDrvdAttr14": "riskyMrktSrcInd : 1",
"strDrvdAttr15": "jntOwnInd : 0",
"strDrvdAttr16": "expL3CallInd : 0",
"strDrvdAttr17": "lnsFPCallInd : 0",
"strDrvdAttr18": "hasCDorIRA : 0"
}
],
"strategyType": "DepositDM"
}
]
}
}
}
I was only interested in extracting values of the keys "strDrvdAttr02", "strDrvdAttr04". I have used flatten before for much simpler JSON but this is too complex for me. I was trying to do nested flatten like below but don't think this will work:
WITH DATA2 AS
(
WITH DATA1 AS
(
SELECT
APLN_ID
,parse_json("DMP_OUTP_VAL") AS json
FROM "SFAAP"."V_SOT_DIRBNK_CRSPRD_FRD_ALL"."VC_EDP_DECSN_LOG"
WHERE "DMP_CALL_TYP_CDE"='DEPOSITDM'
AND APLN_ID = 'XXXXXXXXX'
)
SELECT
APLN_ID
,parse_json(f.value) AS mson
FROM DATA1 d
,lateral flatten(input=>d.json) f
)
SELECT
APLN_ID
,f.value
FROM DATA2 d
,lateral flatten(input=>d.mson) f
I am not able to think of any simpler way to extract those 2 attributes which are kind of sitting in a deeper nested JSON. Hence why looking for taking an expert help. Any comment/help much appreciated. Thank you.
Please try this
select value:depositsStrategyOutputVOs[0]:depositsApplicantDescnVOs[0]:strDrvdAttr02 , value:depositsStrategyOutputVOs[0]:depositsApplicantDescnVOs[0]:strDrvdAttr04 from( from(
select parse_json('{
"depositsDMPResponseVO": {
"depositsApplicationRsnsVO": {
"applicationID": "YYYYYYY",
"applicationRefNbr": "XXXXXXXXX",
"depositsStrategyOutputVOs": [
{
"appDescnTms": "2020-08-18T08:07:00Z",
"depositsAppDecisionVO": {
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
"depositsApplicantDescnVOs": [
{
"applicantDecisionsRuleVOs": [
{
"decision": "AP",
"decisionType": "CIP",
"finalDecision": false,
"reasonCodes": [],
"rule": true,
"ruleName": "DefaultCIP",
"strategyName": "DefaultCIP",
"weight": 100
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": true,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
{
"decision": "AP",
"decisionType": "CIP",
"finalDecision": false,
"reasonCodes": [],
"rule": false,
"ruleName": "DefaultCIP",
"strategyName": "DefaultCIP",
"weight": 100
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": true,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
}
],
"applicantModelScoreVOs": [
{
"modelId": "CHEX",
"reasonCd": [
"AX",
"AP",
"AD",
"AB",
null
],
"scoreNumber": "0576"
}
],
"applicantNbr": "DBAPPLCNT5920115",
"cipPrimVerifySrc": "LNIID",
"cipVerifyBy": "LexisNexis",
"cipVerifyMode": "NDOC",
"strDrvdAttr01": "isMktSrcHghRsk : 1",
"strDrvdAttr02": "totRskVal : 11",
"strDrvdAttr03": "isBnkCust : 0",
"strDrvdAttr04": "bnkCustTen : 0",
"strDrvdAttr05": "hasChkPrdct : 1",
"strDrvdAttr06": "isCrdCust : 0",
"strDrvdAttr07": "newTMXRskVal : 5",
"strDrvdAttr08": "TMXRskVal : 4",
"strDrvdAttr09": "newLNFPRskVal : 2",
"strDrvdAttr10": "LNFPRskVal : 1",
"strDrvdAttr11": "newEMAGRskVal : 4",
"strDrvdAttr12": "EMAGRskVal : 4",
"strDrvdAttr13": "tenureRskVal : 3",
"strDrvdAttr14": "riskyMrktSrcInd : 1",
"strDrvdAttr15": "jntOwnInd : 0",
"strDrvdAttr16": "expL3CallInd : 0",
"strDrvdAttr17": "lnsFPCallInd : 0",
"strDrvdAttr18": "hasCDorIRA : 0"
}
],
"strategyType": "DepositDM"
}
]
}
}
}')) as src,
lateral flatten(input => src.$1:depositsDMPResponseVO);
Unfortunately, you have a few unnecessary arrays in there, so you do need the flattens, but you can do that like joins...like this:
WITH x AS (
SELECT parse_json('{
"depositsDMPResponseVO": {
"depositsApplicationRsnsVO": {
"applicationID": "YYYYYYY",
"applicationRefNbr": "XXXXXXXXX",
"depositsStrategyOutputVOs": [
{
"appDescnTms": "2020-08-18T08:07:00Z",
"depositsAppDecisionVO": {
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
"depositsApplicantDescnVOs": [
{
"applicantDecisionsRuleVOs": [
{
"decision": "AP",
"decisionType": "CIP",
"finalDecision": false,
"reasonCodes": [],
"rule": true,
"ruleName": "DefaultCIP",
"strategyName": "DefaultCIP",
"weight": 100
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": true,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
{
"decision": "AP",
"decisionType": "CIP",
"finalDecision": false,
"reasonCodes": [],
"rule": false,
"ruleName": "DefaultCIP",
"strategyName": "DefaultCIP",
"weight": 100
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": false,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
},
{
"decision": "RV",
"decisionType": "FRD",
"finalDecision": true,
"reasonCodes": [
"DO6001"
],
"rule": false,
"ruleId": "R1002",
"ruleName": "WebChk NewCust TotRsk",
"strategyName": "Web Checking Application Review",
"weight": 2705
}
],
"applicantModelScoreVOs": [
{
"modelId": "CHEX",
"reasonCd": [
"AX",
"AP",
"AD",
"AB",
null
],
"scoreNumber": "0576"
}
],
"applicantNbr": "DBAPPLCNT5920115",
"cipPrimVerifySrc": "LNIID",
"cipVerifyBy": "LexisNexis",
"cipVerifyMode": "NDOC",
"strDrvdAttr01": "isMktSrcHghRsk : 1",
"strDrvdAttr02": "totRskVal : 11",
"strDrvdAttr03": "isBnkCust : 0",
"strDrvdAttr04": "bnkCustTen : 0",
"strDrvdAttr05": "hasChkPrdct : 1",
"strDrvdAttr06": "isCrdCust : 0",
"strDrvdAttr07": "newTMXRskVal : 5",
"strDrvdAttr08": "TMXRskVal : 4",
"strDrvdAttr09": "newLNFPRskVal : 2",
"strDrvdAttr10": "LNFPRskVal : 1",
"strDrvdAttr11": "newEMAGRskVal : 4",
"strDrvdAttr12": "EMAGRskVal : 4",
"strDrvdAttr13": "tenureRskVal : 3",
"strDrvdAttr14": "riskyMrktSrcInd : 1",
"strDrvdAttr15": "jntOwnInd : 0",
"strDrvdAttr16": "expL3CallInd : 0",
"strDrvdAttr17": "lnsFPCallInd : 0",
"strDrvdAttr18": "hasCDorIRA : 0"
}
],
"strategyType": "DepositDM"
}
]
}
}
}') as payload_json)
select f2.value:strDrvdAttr02::varchar,
f2.value:strDrvdAttr03::varchar
from x,
lateral flatten(input => x.payload_json:depositsDMPResponseVO:depositsApplicationRsnsVO:depositsStrategyOutputVOs) f,
lateral flatten(input => f.value:depositsApplicantDescnVOs) f2;

How do I iterate over CIDR blocks in JQ?

Basically I'm trying to iterate through my AWS security groups to find any CIDR's using 0.0.0.0/0.
Here is my example JSON file:
{
"SecurityGroups": [
{
"IpPermissionsEgress": [],
"Description": "AWS OpsWorks load balancer - do not change or delete",
"IpPermissions": [
{
"PrefixListIds": [],
"FromPort": 22,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 22,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 80,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 80,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 443,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 443,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
}
],
"GroupName": "AWS-OpsWorks-LB-Server",
"OwnerId": "056146032236",
"GroupId": "sg-7dd13739"
},
{
"IpPermissionsEgress": [
{
"IpProtocol": "-1",
"PrefixListIds": [],
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"UserIdGroupPairs": [],
"Ipv6Ranges": []
}
],
"Description": "SG for bastion hosts",
"Tags": [
{
"Value": "bastion-host-sg",
"Key": "Name"
}
],
"IpPermissions": [
{
"PrefixListIds": [],
"FromPort": 80,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 80,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 1991,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 1991,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 8080,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 8080,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 1194,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 1194,
"IpProtocol": "udp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 22,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 22,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": [
{
"CidrIpv6": "::/0"
}
]
},
{
"PrefixListIds": [],
"FromPort": 30,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": -1,
"IpProtocol": "icmp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 1194,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 1194,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 53,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 53,
"IpProtocol": "udp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 53,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 53,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 443,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": 443,
"IpProtocol": "tcp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
},
{
"PrefixListIds": [],
"FromPort": 8,
"IpRanges": [
{
"CidrIp": "0.0.0.0/0"
}
],
"ToPort": -1,
"IpProtocol": "icmp",
"UserIdGroupPairs": [],
"Ipv6Ranges": []
}
],
"GroupName": "bastion-host-sg",
"VpcId": "vpc-effd0e8a",
"OwnerId": "056146032236",
"GroupId": "sg-0f60196a"
}
]
}
Here is the command I'm trying to run, but get an error:
$ cat sg-small.json | jq '.SecurityGroups[].IpPermissions[].IpRanges[] | map(select(any(.CidrIp == "0.0.0.0/0")))'
jq: error (at <stdin>:227): Cannot iterate over string ("0.0.0.0/0")
Any thoughts as to why this is happening. That method seems to work for other things that aren't IP addresses.
Your expression:
.SecurityGroups[].IpPermissions[].IpRanges[]
is just a stream of CidrIp objects, so that's not what you want.
The following will select the SecurityGroups that meet the criterion:
.SecurityGroups[]
| select(any( .IpPermissions[].IpRanges[]; .CidrIp == "0.0.0.0/0"))
Whether this is precisely what you want is unclear since you haven't specified that. Please see http://stackoverflow.com/help/mcve
The reason you're seeing the error
Cannot iterate over string ("0.0.0.0/0")
is because with your data the first portion of your filter
.SecurityGroups[].IpPermissions[].IpRanges[]
generates a sequence of objects
{
"CidrIp": "0.0.0.0/0"
}
...
The map portion of your filter iterates over the values in each of these objects, passing
"0.0.0.0/0"
to the expression select(any(.CidrIp == "0.0.0.0/0")) where any tries to iterate over all the values within the string and fails with the error you observe.
If you only want to see a sequence of {"CidrIp":...} objects as above you can eliminate the map and any:
.SecurityGroups[].IpPermissions[].IpRanges[]
| select(.CidrIp == "0.0.0.0/0")
If you would rather collect those objects into an array you could remove the any and move some of the iteration into the map e.g.
.SecurityGroups
| map(.IpPermissions[].IpRanges[] | select(.CidrIp == "0.0.0.0/0"))
producing
[
{
"CidrIp": "0.0.0.0/0"
},
....
The explict construction of the result array is easier to see if you replace map with its definition. Since map(f) is defined as [ .[] | f ] the above filter is the same as this one:
.SecurityGroups
| [ .[] | .IpPermissions[].IpRanges[] | select(.CidrIp == "0.0.0.0/0") ]

MongoDb query to access array json

EDIT:
INPUT : nodes DB is
db.nodes.insert([
{ "ACTIVE" : 1,
"GEOLOCATION": {
"GEO_CODE": [],
"ACTIVE_GEOLOCATION": false
},
"META": {
"CATEGORY": "levis",
"DESCRIPTION": "dsad",
"PRIVACY": "PUBLIC",
"TEMPLATE_NAME": "B",
"TEMPLATE_GROUP": "Product",
"KEYWORDS": [
"sda"
],
"CREATEDBY": "",
"SUBCATEGORY": "Blue",
"PRODUCT_TEMPLATE_TYPE": "Consumable",
"UOM": "",
"TEMPLATE_SUBGROUP": ""
},
"VARIENTS": [
{
"COMMENT": "Demo",
"INDEX": 0,
"NAME": "Brand",
"IS_PARENT": false,
"DATATYPE": "Text",
"ACCESS": "PUBLIC",
"PARENT_VARIENT": "Parem",
"TYPE": "PERMANENT"
},
{
"COMMENT": "Demo",
"INDEX": 0,
"NAME": "Account",
"IS_PARENT": false,
"DATATYPE": "Text",
"ACCESS": "PUBLIC",
"PARENT_VARIENT": "Parem",
"TYPE": "PERMANENT"
},
{
"COMMENT": "Demo",
"INDEX": 0,
"NAME": "Price",
"IS_PARENT": false,
"DATATYPE": "Text",
"ACCESS": "PUBLIC",
"PARENT_VARIENT": "Parem",
"TYPE": "PERMANENT"
},
]
}
])
Input:
if (Meteor.isServer) {
var nodeDB = new Meteor.Collection('nodes');
Meteor.startup(function () {
// code to run on server at startup
});
var p1=nodeDB.find({"ACTIVE" : 1, "VARIENTS.ACCESS" : "PUBLIC"}, { "VARIENTS.NAME": 1, _id : 0 });
var p2=p1.fetch();
var arr1=[];
var arr2=[];
for (i=0;i <p2.length;i++)
{
//console.log(p2[i].VARIENTS);
arr1[i]=p2[i].VARIENTS;
}
var dict=(arr1[1]);
// console.log(x.length);
console.log(arr1.NAME);
Meteor.startup(function () {
// code to run on server at startup
});
}
Result:
[ [ { COMMENT: 'Demo',
I20150521-15:50:47.855(5.5)? INDEX: 0,
I20150521-15:50:47.856(5.5)? NAME: 'Brand',
I20150521-15:50:47.856(5.5)? IS_PARENT: false,
I20150521-15:50:47.856(5.5)? DATATYPE: 'Text',
I20150521-15:50:47.856(5.5)? ACCESS: 'PUBLIC',
I20150521-15:50:47.856(5.5)? PARENT_VARIENT: 'Parem',
I20150521-15:50:47.856(5.5)? TYPE: 'PERMANENT' },
I20150521-15:50:47.856(5.5)? { COMMENT: 'Demo',
I20150521-15:50:47.857(5.5)? INDEX: 0,
I20150521-15:50:47.857(5.5)? NAME: 'Account',
I20150521-15:50:47.857(5.5)? IS_PARENT: false,
I20150521-15:50:47.857(5.5)? DATATYPE: 'Text',
I20150521-15:50:47.857(5.5)? ACCESS: 'PUBLIC',
I20150521-15:50:47.857(5.5)? PARENT_VARIENT: 'Parem',
I20150521-15:50:47.857(5.5)? TYPE: 'PERMANENT' },
I20150521-15:50:47.857(5.5)? { COMMENT: 'Demo',
I20150521-15:50:47.858(5.5)? INDEX: 0,
I20150521-15:50:47.858(5.5)? NAME: 'Price',
I20150521-15:50:47.858(5.5)? IS_PARENT: false,
I20150521-15:50:47.858(5.5)? DATATYPE: 'Text',
I20150521-15:50:47.858(5.5)? ACCESS: 'PUBLIC',
I20150521-15:50:47.858(5.5)? PARENT_VARIENT: 'Parem',
I20150521-15:50:47.859(5.5)? TYPE: 'PERMANENT' } ] ]
Problem: Result required is only NAME parameters in an array.How the query should be modified?
Mongo Query:-
db.nodes.aggregate([
{"$group": {"_id": "$VARIENTS.NAME"}},
{"$project": {"_id": 0, "TEMPLATE_NAME": "$_id"}}
]);
Mongo Result :-
{
"result" : [
{
"TEMPLATE_NAME" : [
"Brand",
"Account",
"Price"
]
}
],
"ok" : 1
}

Deserialize twitter JSON with JSON.NET in C# to fetch hashtags

Maybe I am repeating this question but I am trying this out for the first time and I can't find anything exactly like my situation.. I am coding in C# and using JSON.NET to deserialize a json. The json file is coming from twitter as a response to this GET request:
https://api.twitter.com/1/statuses/home_timeline.json?include_entities=true
The json is a list of 20 latest tweets (json objects) from a given user's twitter timeline and the format of a single json object is like this:
{
"created_at": "Thu Sep 20 10:25:39 +0000 2012",
"id": 248729631476314100,
"id_str": "248729631476314112",
"text": "Ask the experts and learn what's new with v.2.2 at at #MongoDBPune (http://t.co/o5BA7zd6) and #MongoDBBangalore (http://t.co/7q3E2MBq)",
"source": "Socialrithmic",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 18080585,
"id_str": "18080585",
"name": "mongodb",
"screen_name": "MongoDB",
"location": "",
"url": "http://mongodb.org/",
"description": "High-performance, open source, schema-free document-oriented database | www.facebook.com/MongoDB",
"protected": false,
"followers_count": 24999,
"friends_count": 16,
"listed_count": 1582,
"created_at": "Fri Dec 12 17:21:18 +0000 2008",
"favourites_count": 6,
"utc_offset": -18000,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"verified": false,
"statuses_count": 1669,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "529747",
"profile_background_image_url": "http://a0.twimg.com/profile_background_images/619655093/767dji3m3k684nza7w9z.png",
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/619655093/767dji3m3k684nza7w9z.png",
"profile_background_tile": false,
"profile_image_url": "http://a0.twimg.com/profile_images/2452709870/wo2h8r0qy8d5lsxe5lgd_normal.png",
"profile_image_url_https": "https://si0.twimg.com/profile_images/2452709870/wo2h8r0qy8d5lsxe5lgd_normal.png",
"profile_link_color": "43B02A",
"profile_sidebar_border_color": "829D5E",
"profile_sidebar_fill_color": "99CC33",
"profile_text_color": "3E4415",
"profile_use_background_image": true,
"default_profile": false,
"default_profile_image": false,
"following": true,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweet_count": 1,
"entities": {
"hashtags": [
{
"text": "MongoDBPune",
"indices": [
55,
67
]
},
{
"text": "MongoDBBangalore",
"indices": [
95,
112
]
}
],
"urls": [
{
"url": "http://t.co/o5BA7zd6",
"expanded_url": "http://soc.ai/ZV",
"display_url": "soc.ai/ZV",
"indices": [
69,
89
]
},
{
"url": "http://t.co/7q3E2MBq",
"expanded_url": "http://soc.ai/ZW",
"display_url": "soc.ai/ZW",
"indices": [
114,
134
]
}
],
"user_mentions": []
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false
}
I use this code to get the (deserialized) list:
List<JsonObject> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JsonObject>>(response);
where 'response' holds my json.When I inserted a breakpoint and observed the json objects inside 'list', I found this:
{
"created_at": "Thu Sep 20 10:25:39 +0000 2012",
"id": 248729631476314100,
"id_str": "248729631476314112",
"text": "Ask the experts and learn what's new with v.2.2 at at #MongoDBPune (http://t.co/o5BA7zd6) and #MongoDBBangalore (http://t.co/7q3E2MBq)",
"source": "Socialrithmic",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": [
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
],
[
[]
]
],
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweet_count": 1,
"entities": [
[
[
[
[
[]
],
[
[
[],
[]
]
]
],
[
[
[]
],
[
[
[],
[]
]
]
]
]
],
[
[
[
[
[]
],
[
[]
],
[
[]
],
[
[
[],
[]
]
]
],
[
[
[]
],
[
[]
],
[
[]
],
[
[
[],
[]
]
]
]
]
],
[
[]
]
],
"favorited": false,
"retweeted": false,
"possibly_sensitive": false
}
I intend to collect ALL the hashtags from all the 20 json objects..So essentially I need to navigate inside entities to hashtags to text. But as seen above, the deserialization is only partial. It is not deserializing any nested stuff.
How do I fix this? Please help!
Good heavens! Got it from this stackoverflow question. Thanks #chill182!
Here's how you do it:
ArrayList hashtags = new ArrayList();
JArray jsonDat = JArray.Parse(response);
for(int x = 0; x < jsonDat.Count(); x++)
{
JObject entity = JObject.Parse(jsonDat[x]["entities"].ToString());
JArray arrHashtags = JArray.Parse(entity["hashtags"].ToString());
for(int i=0; i < arrHashtags.Count(); i++)
{
JObject hashtagstuff = JObject.Parse(arrHashtags[i].ToString());
hashtags.Add(hashtagstuff["text"].ToString());
}
}
Don't forget to include Linq in the namespace :)
using Newtonsoft.Json.Linq;