Skip to content

Is there a way to compare two strings in JOLT? #1274

Description

@KarthikND01

I have below JSON, where I want to compare "categoryType" value with categories' object's "type" and pick up the matching object. Please find the details below,

Input

{
"categoryType": "A",
"categories": [
{
"type": "A",
"issue": "1"
},
{
"type": "B",
"issue": "2"
},
{
"type": "C",
"issue": "3"
}
]
}

Expected Output

{
"category" : {
"type" : "A",
"issue" : "1"
}
}

My JOLT Configuration

[
{
"operation": "shift",
"spec": {
"categories": {
"*": {
"type": {
"@(3,categoryType)": {
"@2": "category"
}
}
}
}
}
}
]

And the output I am getting is as below, which is incorrect because @(3,categoryType) value is "A", so it should only pick up the "type" matching the value "A". If I replace "@(3,categoryType)" with "A", it will pick up only one object matching the type "A". Any idea how to resolve this issue?
{
"category" : [ {
"type" : "A",
"issue" : "1"
}, {
"type" : "B",
"issue" : "2"
}, {
"type" : "C",
"issue" : "3"
} ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions