Need help parsing returned data

I do a asynchttpPost and I need to parse the returned data. I can print it to the log for now. I just have no idea how to parse data in Groovy, perl, tcl sure, not Groovy.

The data is returned as a string of the form:

tag1=tag details\n
tag2=tag2 details\n

I only need the tag data, no details. I call this function in the initialize code and want to use the collection of tags returned to set the enum list of an application parameter. Don't know how to do the second part either, but first I'd like to parse the data.

How can I do this? Pointers to documentation works as well. I've looked, but not been successful.


There's the official Groovy documentation, but there are lots of third-party tutorials. What you're looking for are operations you can perform on strings.

In your case, it appears the split() method may be particularly helpful. You could split it on '\n' to get a list of lines in your string, then you could use something like .indexOf('=') to find the first equals sign (Iooks like that's your delimeter?) and .subString(0, indexOfTheFirstEqualsSignYouFoundBefore) to get the first part.

This is general Groovy, not Hubitat-specific. Hubitat denies access to some built-in Groovy methods as part of its sandbox, but I don't think any string methods are restricted, so whatever else you can find in the docs (these are just a couple ideas) may also work, depending on how you want to approach the parsing.


Ok that helped a lot. I'm able to get this to work for a predefined string:

class Example {
static void main(String[] args) {
String a = " DavidEmail=mailto://\nDavidText=mailto://";
String[] str;
str = a.split('\n');

  for( String values in str ) {
  int b = values.indexOf("=");
  print(" "+b);
  String tag = values.substring(0,b);
  println(" "+tag)


Tag is what I"m looking for. However, when I try to use the response object, I can't find any documentation on how to get the data out of the model. I can print it to the log with log.debug, so obviously log.debug know how to do this.

The data is coming back as text/plain if that matters.

EDIT: I did find:

String returnedTags = response.getData()

However, this spilts the returned text by character and I get an array of single character strings. I just want the unadulterated string returned by the webserver.

Join, just makes it all go away.