Using jsonpath with a JSON input in Pentaho Data Integration/Kettle I am trying and failing to retrieve the objects names:
{
"otherobject":"dontcare",
"objectid_01":{
"property_01":"a",
"property_02":["s","t"]
},
"objectid_02":{
"property_01":"b",
"property_02":["u","v"]
}
}
I am able to extract ["a","b"] with $..property_01 but I would also need to get the names/ids/keys/whatever they are called ["objectid_01","objectid_02"] with jsonpath.
Greatly appreciate your help in advance!
you can try:
$.objectid_01.property_01
$.objectid_01.property_02
or
$.objectid_01.*.property_02
This syntax works in json input!
Related
I'm using the NoCode-app Flutterflow - and I need a piece of code ;) to sort a firestore-collection. I'm sure it can't be that hard, but I'm trying this for 2 days now...
I want the function to return a sorted list, based on a string-argument.
When I create a "custom function" (that's how a piece of code is called in FlutterFlow) I get this template:
import 'dart:math' as math;
List<DocumentReference> sortImages(
List<DocumentReference> listdocument,
String sortBy,
) {
return listdocument; '<<< what comes here? How do I sort?
}
How do I sort "sortImages" now by the argument "sortBy" and return it?
As you see I don't really have an idea of flutter/darts, and a NoSQL-db is also new to me... but I keep fighting to learn more every day!
Thanks a lot!
sorry if it's too late, but have you read this post?
How can I sort a list of strings in Dart?
There is a explanation of how to order string with different alternatives. This example should work in your custom function:
final List<String> fruits = <String>['bananas', 'apples', 'oranges'];
fruits.sort();
print(fruits);
Cheers!
Ariel-.
I'm new to VTL and AWS appsync and try to get my head around how things are working.
The maps that are representing Steps in a List should have the property id with a UUID before there are stored in DynamoDB. To accomplish this I tried to iterate over the array and access the put method on the map like in the example below.
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key": {
"id" : $util.dynamodb.toDynamoDBJson($util.autoId())
},
#set($input = $util.dynamodb.toMapValues($ctx.args.input))
#set($input.createdAt = $util.dynamodb.toDynamoDB($util.time.nowISO8601()))
#foreach($step in $input.steps)
$step.put('id', $util.dynamodb.toDynamoDBJson($util.autoId())))
#end
"attributeValues": $util.toJson($input)
}
my second try:
#foreach($step in $input.steps)
#set($step.id = $util.dynamodb.toDynamoDBJson($util.autoId()))
#end
but still, for no reason, my maps do not have the property id.
Is there maybe the problem what the foreach loop is giving me just a copy of the map I try to modify and not the original object?
Thank you for your time!
Hopefully, my question will serve all newbies to VTL and appsync
They do, it's just that the toMapValues utility method is returning you DynamoDB types.
So if "input.steps" is supposed to be a list what you're gonna get in there is an object like {"L": [ ... ]}
Try this:
#foreach($step in $input.steps.L)
$step.put('id', $util.dynamodb.toDynamoDBJson($util.autoId())))
#end
I have a top level attribute and I want to simultaneously update multiple nested attributes. The params I am passing in are:
{
"TableName":"LOCAL-Table",
"Key":{
"id":"1"
},
"UpdateExpression":"SET #param.#eb321fb16aab1745c55a8659be811f2d = :valeb321fb16aab1745c55a8659be811f2d , #param.#6e3c283fb60480af627ede2758e8e983 = :val6e3c283fb60480af627ede2758e8e983",
"ExpressionAttributeValues":{
":valeb321fb16aab1745c55a8659be811f2d":{
...
},
":val6e3c283fb60480af627ede2758e8e983":{
...
}
},
"ExpressionAttributeNames":{
"#eb321fb16aab1745c55a8659be811f2d":"eb321fb16aab1745c55a8659be811f2d",
"#6e3c283fb60480af627ede2758e8e983":"6e3c283fb60480af627ede2758e8e983",
"#param":"param"
},
"ReturnValues":"UPDATED_NEW"
}
It works when updating a single attribute, but when I put 2 in I get an error stating:
The document path provided in the update expression is invalid for update
Any help greatly appreciated.
Thanks
Actually, this does work, the problem was related to poorly sequenced promises resulting in a race condition.
I have a situation where I have json String that has a child as Array that contains only Strings. Is there as way I can get the object reference of the arrays that contains a specific String.
Example:
{ "Books":{
"History":[
{
"badge":"y",
"Tags":[
"Indian","Culture"
],
"ISBN":"xxxxxxx",
"id":1,
"name":"Cultures in India"
},
{
"badge":"y",
"Tags":[
"Pre-historic","Creatures"
],
"ISBN":"xxxxxxx",
"id":1,
"name":"Pre-historic Ages"
}
]
}
}
To Achieve:
From the above JSON String, need to get all books in History which contains "Indian" inside the "tags" list.
I am using JSONPATH in my project but If there is other API that can provide similar functionality, any help is welcome.
If you're using Goessner JSONPath, $.Books.History[?(#.Tags.indexOf('Indian') != -1)] as mentioned by Duncan above should work.
If you're using the Jayway Java port (github.com/jayway/JsonPath), then
$.Books.History[?(#.Tags[?(# == 'Indian')] != [])] or more elegantly, use the in operator like this $.Books.History[?('Indian' in #.Tags)]. Tried them both here.
Assuming you are using Goessner JSONPath (http://goessner.net/articles/JsonPath/) the following should work:
$.Books.History[?(#.Tags.indexOf('Indian') != -1)]
According to the Goessner site, you can use underlying JavaScript inside the ?() filter. You can therefore use the JavaScript indexOf function to check if your Tags array contains the tag 'Indian'.
See a working example here using this JSONPath query tester:
http://www.jsonquerytool.com/sample/jsonpathfilterbyarraycontents
Did you try to use underscoreJS ? You can get the Indian books like this :
var data = {"Books:"....};
var indianBooks = _.filter(data.Books.History, function(book) { return _.contains(book.Tags, "Indian"); })
I am working on a XML parser and I have the following problem :
I have this function which gather some tags value, for example movie title and release date :
func whatever() map[string]interface{} {
}
And I would like it to return something of this form :
[map[title:Movie01] map[title:Movie02]]
Without changing the return type.
All I have for now is :
map[title:Movie01]
And obviously I cannot have duplicate "title" key in one single map.
Can you help me on this ? It's been bothering me for a couple of hours now.
For the record then, as I mentioned in the comments you could try returning a slice of maps such as
func whatever() []map[string]interface{} {
}
Though depending on your data you might find a better solution in defining an appropriate struct for your domain and returning that.