Pattern matching

it is

{
"beta": {
          "version": "0.9.0-beta2",
          "build_id": "20211019-142857/0.9.0-beta2-gc6f3536"
           }
}

3 times so the code i am using now will work

Normally yes, but in this case it was just a simple json response which only contained the word once :slight_smile:

Personally I'd prefer to be confirming the key "beta".... But it's not a major thing...

2 Likes

Seems you're already sorted but it looks like you are having a (Lazy)Map , so containsKey is available

    Map response = [ "stable": "data", "beta123": "some more"]
    assert response.containsKey("stable") //key stable exists
    assert !response.containsKey("beta") //key beta does not exists

    assert response.keySet().any { key -> key =~ "^beta.*"} //key starting with beta exists
    assert !response.keySet().any { key -> key =~ "^test.*"} //key starting with test does not exists
4 Likes

Oh that's interesting! Thanks for the tip!

Download the Hubitat app