Question

Unknown Array Format to Attributes

  • 17 January 2019
  • 4 replies
  • 0 views

Userlevel 3
Badge +17

I have an attribute that contains the following string format:

[url='thisurl', version='1', timestamp='2019-01-15T08:27:30.382Z', status=[operation='operational', mode='local', state='out', generalError='no', generalWarning='yes', errorList=[], warningList=[warning='inactive', state='unknown']]]

 

I want to convert this string to attributes => values:

url => thisurl
version => 1
timestamp =>2019-01-15T08:27:30.382Z
status => [operation='operational', mode='local', state='out', generalError='no', generalWarning='yes', errorList=[], warningList=[warning='inactive', state='unknown']]

 

Can I do this with some kind of regex Transformer and what should it look like?

 

 

 


4 replies

Userlevel 4
Badge +25

It kinda looks like JSON, but it isn't. That means if you can get it to JSON you can use the JSONFlattener to turn it into attributes.

Some of that conversion is simple, but part of it requires some regex magic.

none2none.fmw

I'm sure @takashi or @david_r will come up with a single regex that does it all :)

 

Userlevel 3
Badge +17

It kinda looks like JSON, but it isn't. That means if you can get it to JSON you can use the JSONFlattener to turn it into attributes.

Some of that conversion is simple, but part of it requires some regex magic.

none2none.fmw

I'm sure @takashi or @david_r will come up with a single regex that does it all :)

 

My example was not complete so I had to make some changes. But your example helped a lot.

Userlevel 3
Badge +17

My example was incorrect. My workbench works now on the following string: 

[url='this/url/has spaces', version='1', timestamp='2019-01-15T08:27:30.382Z', status=[operation='operational', mode='local', state='out', generalError='no', generalWarning='yes', Â errorList=[], warningList=[]]]

This has an empty errorList. But the errorList is not a key->value type so it looks like this:

[url='this/url/has spaces', version='1', timestamp='2019-01-15T08:27:30.382Z', status=[operation='operational', mode='local', state='out', generalError='no', generalWarning='yes', Â errorList=['Spaces here', 'Only values no attributes'], warningList=['One item list']]]

Changing it to this is invalid json:

{"url":"this/url/has spaces", "version":"1", "timestamp":"2019-01-15T08:27:30.382Z", "status":{"operation":"operational", "mode":"local", "state":"out", "generalError":"no", "generalWarning":"yes", Â "errorList":{"Spaces here", "Only values no attributes"}, "warningList":{"One item list"}}}

 

Can someone help me with the last bit?

0684Q00000ArKPXQA3.png

 

This is the almost working workbench:

 

24354-translate errorList.fmw

Badge

Hi @jkr_da

 

If your string is always in that format then you can use a python caller to do it all in one transformer.

Basically if split the string into two halves where you have "status=", you have the pairs in the 1st half which can be split further into the attributes and values and the status value as a string in the 2nd half.

pythoncaller.fmw

Reply