cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Build string jSon and workflow variables not working

Jump to solution

Hi,

I am having an issue using a the build string action to compile my jSon and insert workflow variables within my jSon.

If I compile the jSon without inserting any variables it works fine.

I only thing I can see is a potential conflict is when using the curly braces within my jSon?

Any help would be greatly appreciated.

Labels: (1)
Tags (2)
0 Kudos
Reply
8 Replies
Highlighted
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

I think its a BUG, please have a look at Cannot use a variable in a Web Request action body 

0 Kudos
Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

That's true. It's a bug. I'm doing using the following workaround:

  1. Create a JSON variable, but first and last bracket are replaced by the _bracket and bracket_
  2. Then I use "Regular Expression" actions to replace _bracket and bracket_ with { and }.

Alternatively you can try to use this set of actions:

  1. Remove opening and closing bracket from your JSON.
  2. Use "regular expression" action to split your JSON into array.
  3. Use "add item to collection" to add the 0 element: { and 999 element: }
  4. Then use "join items in collection" action to receive your working JSON string.

Regards,

Tomasz

Regards, Tomasz Poszytek
0 Kudos
Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

Hello Tomaz,

Thanks for the workaround :-). Another easy workaround is suggested in the Link  . Especially for someone who does not understand Regular expression. 

Regards,

Clavin Fernandes

Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

There is even an easier. And come on - this "regular expression" is a simple replace. Not a big deal

  1. Create your JSON string, but don't use opening and closing brackets, but replace them with ex.:
    1. _leftBracket
    2. rightBracket_
      So it will look like: _leftBracket"attr":"value","attr":"value", "attr":{"attr":value"}rightBracket_
  2. Then use regular expression, to replace: _leftBracket with {
  3. Then use regular expression, to replace: rightBracket_ with }

Simple, isn't it?

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

Yep, "regular expression" is easy for us, but not for Power user's. It really scare's them.


Step 1: Create a JSON variable using Build String action, but replace the first and last bracket with [ and ].

Step 2: Then use "Replace Sub-string in String" to Replace [ with {.

Step 3: Use the Output of variable from Step 3 in another "Replace Sub-string in String" action to Replace ] with }.

Perhaps this tread can be converted into Blog Post as it has all the possible workarounds ;-)

Regards,

Clavin Fernandes

Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

With all respect, but if "Regular expression" scares some "Power Users" then... no they are not "Power Users"

Regards, Tomasz Poszytek
0 Kudos
Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

Perhaps you are right ;-) But the skill set may vary 

0 Kudos
Reply
Workflow Hero

Re: Build string jSon and workflow variables not working

Jump to solution

Clavin, one more thing. Your solution, with replacing square brackets with { is good unlesssss... you have square

brackets inside your JSON object. Be aware, that square brackets are used for arrays.

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply