Skip to main content
Question

Unknown Array Format to Attributes


jkr_wrk
Influencer
Forum|alt.badge.img+29

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

redgeographics
Celebrity
Forum|alt.badge.img+50

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 :)

 


jkr_wrk
Influencer
Forum|alt.badge.img+29
  • Author
  • January 18, 2019
redgeographics wrote:

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.


jkr_wrk
Influencer
Forum|alt.badge.img+29
  • Author
  • January 18, 2019

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


Forum|alt.badge.img
  • January 18, 2019

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings