Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for matching values #626

Closed
vectro opened this issue Jul 9, 2018 · 2 comments
Closed

Check for matching values #626

vectro opened this issue Jul 9, 2018 · 2 comments

Comments

@vectro
Copy link

vectro commented Jul 9, 2018

Hi folks,

I am looking for a transform like this:

{
  "input": [
    {
      "a": "123",
      "b": ""
    },
    {
      "a": "",
      "b": "456"
    },
    {
      "a": "789",
      "b": "789"
    },
    {
      "a": "10",
      "b": "11"
    }
  ],
  "expected": [
    {
      "x": "123"
    },
    {
      "x": "456"
    },
    {
      "x": "789"
    },
    {
      "x": "Error!"
    }
  ]
}

This is very similar to the unique values others have mentioned with the added criterion that I want to enforce that there is only one possible value.

One idea I had was to transform the input keys into an object, then check that it has only one key. But I don't see how to match on the number of keys in JOLT?

Thanks as always for this neato tool.

@milosimpson
Copy link
Contributor

I don't see a way to do that. The hard one being the duplicate "789" values.

In theory for the rest you could accumulate all non "" values into a list, and then using modify ask for the size of a each list. But there isn't a dedup the list.

@vectro
Copy link
Author

vectro commented Jul 10, 2018

Thanks Milo. I played around with this a little and came up with this.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "": null,
          "*": "[&2].x.&"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "x": {
          "*": {
            "$": "[&3].x"
          }
        }
      }
    }
  }
]

Which yields a result like this

[ {
  "x" : "123"
}, {
  "x" : "456"
}, {
  "x" : "789"
}, {
  "x" : [ "10", "11" ]
} ]

But I don't see how to go from there. Is there a way in jolt to match on object type?

@jsurls jsurls closed this as completed Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants