Skip to main content
Question

Unknown Array Format to Attributes

  • January 17, 2019
  • 4 replies
  • 5 views

jkr_wrk
Influencer
Forum|alt.badge.img+35

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?

 

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

redgeographics
Celebrity
Forum|alt.badge.img+60
  • Celebrity
  • 3702 replies
  • January 17, 2019

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+35
  • Author
  • 424 replies
  • January 18, 2019

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+35
  • Author
  • 424 replies
  • 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
  • 48 replies
  • 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