Using variables in script to create Json - Newbie help

Padawan
Member
Posts: 55
Joined: Mon Jun 12, 2017 8:48 pm

Re: Using variables in script to create Json - Newbie help

Postby Padawan » Tue Feb 06, 2018 3:30 pm

Switch uses [ and ] characters to indicate the beginning and end of Switch variables. I believe the issue is caused because the square brackets which are used to indicate the json array are confusing switch because it thinks they indicate a Switch variable, while they aren't.

It is possible to escape the square brackets by doubling the opening bracket. In my tests the following works:

Code: Select all

{
"Items": [[{
      "StockItemID": 13185,
      "Quantity": "0001",
      "Ref1": "[Metadata.Text:Path="/root/amount",Dataset="Xml",Model="XML"]"
        }]
}

jan_suhr
Member
Posts: 94
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Using variables in script to create Json - Newbie help

Postby jan_suhr » Tue Feb 06, 2018 11:24 pm

The square brackets around the variables are not the problem. Switch will send the value of the variable to the app. If you run messages with the debug option on you will see how Switch give each variable a value, if it gets wrong there it is something wrong with the variable or with the JSON surrounding the variable.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

jan_suhr
Member
Posts: 94
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Using variables in script to create Json - Newbie help

Postby jan_suhr » Wed Feb 07, 2018 11:30 am

There is a problem with the Square brackets [ ] when used in the Make JSON. Switch has a special use of square brackets and that conflicts with JSON's use of square brackets. And just to escape them doesn't solve it.

I will create a workaround to solve this problem so that we can have correct JSON with JSON arrays working with Switch variables.

Hopefully it will be ready next week on the App Store.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

Redshift
Newbie
Posts: 8
Joined: Thu Dec 21, 2017 2:40 am

Re: Using variables in script to create Json - Newbie help

Postby Redshift » Wed Feb 07, 2018 8:41 pm

Thanks for both your help.


Return to “Scripting”



Who is online

Users browsing this forum: No registered users and 2 guests