How do I assign array of Objects as value to an Attribute in Apache NiFi - mongodb

In Apache NiFi, My Mongo DB is returning Array of Objects as shown below
[
{ fname:john,
city:Nyc
},
{ lname:doe,
city:Nj
}
]
I am trying to assign the entire array of Objects to an Attrbiute using EvaluateJsonPath Processor,
my EvaluateJsonPath configuration is as shown below,but I am getting "EvaluateJsonPath unable to return a scalar" error.
I tried $.* in fullname value, tried changing return type to Scalar and auto detect. still I am getting the same error.
How do I assign the entire array of objects to an attribute in Apache NiFi

In case,if any one is interested
Changing Return type to Json and Fullname value to $.* resolved the issue.

Related

how to insert node in JSON doc in Marklogic using xdmp:node-insert

I want to insert node in a JSON document like this:
{
"fileName": "l",
"user_id": "test",
"requestId": "1232",
"feedbackType": "cpd_mah"
}
Running this code:
let $old := $doc/filename
return
xdmp:node-insert-after($old, object-node{"isSaved": ""})
but this is throwing an error XDMP-CHILDUNNAMED.
I agree with Mads, that using node-insert-child makes more sense with JSON. You can use node-insert-after though. Your attempt is throwing an XDMP-CHILDUNNAMED error because you are passing in an unnamed object node (which is basically an anonymous wrapper for its properties), rather than the named property you'd like to insert. Mads code is giving away how you can make it work:
let $old := doc("/test.json")/filename
return
xdmp:node-insert-after($old, object-node{"isSaved": ""}/isSaved)
Note: if you run it multiple times, it will replace rather than insert, since properties should be unique.
HTH!
JSON properties don't have the concept of a sibling, the way that XML elements do.
A JSON object is basically a map with a set of properties. So, rather than inserting an object as a child node after one of the properties, you want to insert a child node (notice the XPath selecting isSaved from the constructed object) of the JSON document object-node()
let $old := doc("/test.json")/object-node()
return
xdmp:node-insert-child($old, object-node{"isSaved": ""}/isSaved)
A few examples of working with JSON in XQuery from the MarkLogic documentation:
https://docs.marklogic.com/guide/app-dev/json#id_60123

How can you use conv.user.entitlements ? it returns an object but it doesn't show the data

When I use conv.user.entitlements it returns "[ { entitlements: [ [Object] ], packageName: 'com.Company.ProjectName' } ]" to console.log -- is there a way to search the data in Object?
I tried conv.user.entitlements[entitlements], conv.user.entitlements.entitlements, and conv.user.entitlements[0] thinking I can read it like an array but it didn't work and comes back undefined.
Have you tried serializing it to see the structure, e.g.
console.log(`entitlements: ${JSON.stringify(conv.user.entitlements)}`);
Based on the structure posted in comments, accessing specific properties requires navigating through multiple arrays, e.g.:
console.log(entitlements[0].entitlements[0].inAppDetails);
console.log(entitlements[0].entitlements[0].inAppDetails.inAppPurchaseData.purchaseTime);

Data factory lookup (dot) in the item() name

I am having lookup wherein salesforce query is there. I am using elements (item()) in subsequent activities. Till now i had item().name or item().email but now i have item().NVMStatsSF__Related_Lead__r.FirstName which has (dot) in the field name.
How should i parse it through body tag so that it reads it correctly?
So I have the following data in item()
{
"NVMStatsSF__Related_Lead__c": "00QE000egrtgrAK",
"NVMStatsSF__Agent__r.Name": "ABC",
"NVMStatsSF__Related_Lead__r.Email": "geggegg#gmail.com",
"NVMStatsSF__Related_Lead__r.FirstName": "ABC",
"NVMStatsSF__Related_Lead__r.OwnerId": "0025434535IIAW"
}
now when i use item().NVMStatsSF__Agent__r.Name it will not parse because of (dot) after NVMStatsSF__Agent__r. And it is giving me the following error.
'item().NVMStatsSF__Related_Lead__r.Email' cannot be evaluated because property 'NVMStatsSF__Related_Lead__r' doesn't exist, available properties are 'NVMStatsSF__Related_Lead__c, NVMStatsSF__Agent__r.Name, NVMStatsSF__Related_Lead__r.Email, NVMStatsSF__Related_Lead__r.FirstName, NVMStatsSF__Related_Lead__r.OwnerId'.",
"failureType": "UserError",
"target": "WebActivityToAddPerson"
this is because ADF uses '.' for object reading.
Could you find a way to rename the field name which contains '.'?
Seems like you need a built-in function to get the value of an object according to the key. Like getValue(item(), 'key.nestkey'). But unfortunately, seems there isn't such a function. You may need handle your key first.
Finally, it worked. I was being silly.
Instead of taking the value from the child table with the help of (dot) operator I just used subquery. Silly see.
And it worked.

Parse JSON in Drools WHEN block

I am trying to automate the rule creation using Rule Template.
I am using ResultSetGenerator which will get the result set from Database and create the rule.
One of the column(Grade) in the DB table is of type JSON with following value:
{
"grade":"A",
"subjects":["Math","Geography"]
}
I want the use the above JSON in drools WHEN block in the following way.
rule "TEST"
WHEN
s:String(this==#{Grade})
THEN
//DO SOMETHING
How can I parse the Json of the Grade column to get the value for "grade" attribute from it and use it in WHEN block.
Please help.
Thanks
Try assigning the JSON to a Map object instead.
The "subjects" element of the Map object should be able to be assigned to a List object as well.
We have a rulesengine that passes raw JSON as facts, and we parse through the JSON by using Map() in the WHEN section.

Using [array] in a class based DSC resource

I have been creating a few class based custom DSC resources and I am running into the following issue:
Whenever I try to use an array as input for my resource, I get an error.
For example
DscProperty(Mandatory)]
[array]$Products
Would result in the following error when I try to create a MOF file using my resource:
Write-NodeMOFFile : Invalid MOF definition for node 'nodename':
Exceptioncalling "ValidateInstanceText" with "1" argument(s):
"Convert property 'Products' value from type 'STRING[]' to type 'INSTANCE' failed.
The input object for $Products would be (for example):
$Products = #("Windows server 2012", "Windows SQL Server", "Windows 8.1")
I honestly have no idea why the Write-NodeMOFFile function would try to convert the array (it should not need converting, right?) and even if it needed to be converted - why would it convert an array from STRING[] to INSTANCE?
Anyone has a clue as to why this happens?
The only way I got it to work was by creating a long string from my array of strings and then seperating them within the resource.
declare array like this :
[string[]]$product="ddd","dq","dqq"