I'm using jolt + java(https://github.com/bazaarvoice/jolt) to transform an external JSON in a format that I can understand.
My problem is the structure keeps changing and this is making my spec more and more complex.
I want to extract all the fields which are called "path" no matter the structure.
does someone have an idea how can I do that?
Example of structure:
{
"groups": {
"rows": {
"fieldSets": {
"fields": [{
"path": "example"
}]
}
}
}
}
or
{
"groups": {
"rows": {
"rowsets": {
"fieldSets": {
"fields": [{
"path": "example"
}]
}
}
}
}
}
or
{
"groups": {
"fieldSets": {
"fields": [{
"path": "example"
}]
}
}
}
in the end, I just want an array with plain "path" values.
I am also new to the JOLT. Anyway I tried with what I understood from your question. Just try the below spec:
[
{
"operation": "shift",
"spec": {
"groups": {
"rows": {
"fieldSets": {
"fields": {
"*": {
"path": "path"
}
}
}
}
}
}
}
]
If it is not what you are expecting, then please give an output json, so that i can understood what you want.
Related
I'm struggling to find the correct jolt spec to evaluate the values of two keys prior to creating an output. Any ideas?
Input:
{
"ticketInformation": {
"area": "001",
"site": "ABC",
"ticketType": "TC"
}
}
Spec:
[
{
"operation": "shift",
"spec": {
"ticketInformation": {
"area": {
"001": {
"#Works": "OneMatch"
}
},
"ticketType": {
"TC": {
"#OnlyEvaluatingTicketType": "HowToEvalueValuesOfTwoKeys"
}
}
}
}
}
]
Output:
{
"OneMatch" : "Works",
"HowToEvalueValuesOfTwoKeys" : "OnlyEvaluatingTicketType"
}
The desired output is the same as the actual output but ONLY if area=001 AND troubleType=TC.
I guess this is the spec you are looking for
[
{
"operation": "shift",
"spec": {
"ticketInformation": {
"area": {
"001": {
"#(2,ticketType)": {
"TC": {
"#Yes": "BothMatching"
}
}
}
}
}
}
}
]
I am trying to write a jolt transformation for the input below:
Input
[{
"factValues": [
{
uniqeid:"1",
"values":"1234567"
},
{
uniqeid:"1",
"teams":"abcde"
}]
},{
"factValues": [
{
uniqeid:"2",
"values":"6758595"
},
{
uniqeid:"2",
"teams":"medrgeh"
}]
}
]
Excepted Output.
{
"factValues": [{
uniqeid:"1",
"values":'1234567',
"teams":'76599876'
},
{
uniqeid:"2",
"values":'6758595',
"teams":'medrgeh'
}
]
}
Kindly help me to achieve the expected output.json in spec.json. The spec is not transforming as expected output. I want learn how to use attributes inside the string parser
Shifted all the values to the factValues. Then selected the first element from the uniqueid array,
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"uniqeid": "factValues.[&3].uniqeid",
"values": "factValues.[&3].values",
"teams": "factValues.[&3].teams"
}
}
}
}
}, {
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"uniqeid": "=firstElement(#(1,uniqeid))"
}
}
}
}
]
I have a mongodb collection that has 'nested' documents. For example, a document can have the following structure:
{
"condition": {
"parameter": {
"type": "person"
}
}
}
as well as the next one:
{
"condition": {
"conditions": [
{
"conditions": [
{
"parameter": {
"type": "A"
}
},
{
"parameter": {
"type": "B"
}
}
]
},
{
"parameter": {
"type": "C"
}
}
]
}
}
Meaning, each condition sub-document can have multiple conditions within itself.
Now, I'd want to make a 'recursive' query on the type field of each condition, something like ('..' representing the recursion):
{
"$or": [
{"condition.type": "person"},
{"condition..conditions.type": "person"}
]
}
Is there any way to do this in Mongo?
I am having troubles transforming JSON payload into the desired document.
I have following input:
{
"events": [
{
"recipientId": "r0001"
},
{
"recipientId": "r0002"
}
],
"networkResponseTime": 1234
}
Desired output:
{
"events": [
{
"recipientIds": "r0001",
"networkResponseTime": 1234"
},
{
"recipientIds": "r0002",
"networkResponseTime": 1234"
}
]
}
How will the JOLT spec look like for this example?
So far I have smth like this:
[{
"operation": "shift",
"spec": {
"events": {
"*": {
"recipientId": "events[&1].recipientIds"
}
}
}
}]
Spec
[{
"operation": "shift",
"spec": {
"events": {
"*": {
"recipientId": "events[&1].recipientIds",
//
// go back up to the root of the tree, and then
// come back down the key "networkResponseTime", and
// send it's value to "events[&1].networkResponseTime"
"#(2,networkResponseTime)": "events[&1].networkResponseTime"
}
}
}
}]
I have a collection looking somewhat like this:
{
"colors": ["blue","white"],
"items": {
"old": {
"name": "test"
}
"current": {
"name": "new_test"
}
}
},
{
"colors": ["red","green"],
"items": {
"old": {
"name": "test2"
}
"current": {
"name": "new_test2"
}
}
},
Is it possible to use find like this:
db.collection.find({"items": { "old": { "name": "test" } } })
So the command would return:
{
"colors": ["blue","white"],
"items": {
"old": {
"name": "test"
}
"current": {
"name": "new_test"
}
}
}
Is this possible?
Yes, you can use the 'dot notation' to reach into the object:
db.collection.find({"items.old.name": "test" })
The query syntax you used also works, but it has different semantics: It will match the entire subdocument for equality instead of just a single field. For instance, the following query would also return a result:
db.foo.find({"items.old": {"name" : "test"} }),
butdb.collection.find({"items": { "old": { "name": "test" } } }) does not, because items also contains a current field.