Hi All
I have recently upgraded my Switch installation from Spring 2020 to the latest Fall 2023
With that some of the Apps have been upgraded
Since then I had a MAKE JSON command that no longer works, firstly is it possible to roll back the App Version? and if not can anyone identify whats wrong. Reading the notes I think its something to do with the quote marks but not having any luck
Message I see from switch: JSON code failed SyntaxError: Unexpected token / in JSON at position 64
THIS IS MY CODE:
{
"items": [
{
"orderReference": "[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]",
"recipient": {
"address": {
"fullName": "[Database.Text:SQL="SELECT DeliveryContact FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"companyName": "[Database.Text:SQL="SELECT DeliveryCustomerName FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine1": "[Database.Text:SQL="SELECT DeliveryAddress FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine2": "",
"addressLine3": "",
"city": "[Database.Text:SQL="SELECT DeliveryTown FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"county": "",
"postcode": "[Database.Text:SQL="SELECT DeliveryPostcode FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"countryCode": ""
},
"phoneNumber": "",
"addressBookReference": ""
},
"sender": {
"tradingName": "Team Impression Ltd",
"phoneNumber": "01132724800",
"emailAddress": "markca@team-impression.com"
},
"packages": [
{
"weightInGrams": 400,
"packageFormatIdentifier": "parcel",
"customPackageFormatIdentifier": "",
"contents": [
{
"name": "",
"SKU": "",
"quantity": 1,
"unitValue": 0,
"unitWeightInGrams": 0,
"customsDescription": "",
"extendedCustomsDescription": "",
"customsCode": "",
"originCountryCode": "",
"customsDeclarationCategory": "none",
"requiresExportLicence": true
}
]
}
],
"orderDate": "[Database.Text:SQL="SELECT Datedb FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"plannedDespatchDate": "",
"specialInstructions": "",
"subtotal": 0,
"shippingCostCharged": 0,
"otherCosts": 0,
"customsDutyCosts": "",
"total": 0,
"currencyCode": "",
"postageDetails": {
"sendNotificationsTo": "sender",
"serviceCode": "CRL48",
"serviceRegisterCode": "",
"consequentialLoss": "",
"receiveEmailNotification": false,
"receiveSmsNotification": false,
"guaranteedSaturdayDelivery": false,
"requestSignatureUponDelivery": false,
"isLocalCollect": false,
"safePlace": "",
"department": "",
"AIRNumber": "",
"IOSSNumber": "g",
"requiresExportLicense": false,
"commercialInvoiceNumber": "",
"commercialInvoiceDate": "2022-08-24T14:15:22Z"
}
}
]
}
Make JSON
Re: Make JSON
In the latest versions you can use replacement characters to be able to make an JSON array using variables in the code.
Switch uses the Square brackets to define the values from a variable, this conflicts with the JSON array Square brackets and because of that Switch gets confused about the variable values.
So when you define your JSON code in the app all array square brackets has to be replaced with something.
Then when the JSON code is generated Switch will first add the variables and then the proper array square brackets will be put in place. Then the code is parsed to validate it.
Switch uses the Square brackets to define the values from a variable, this conflicts with the JSON array Square brackets and because of that Switch gets confused about the variable values.
So when you define your JSON code in the app all array square brackets has to be replaced with something.
Then when the JSON code is generated Switch will first add the variables and then the proper array square brackets will be put in place. Then the code is parsed to validate it.
-
- Member
- Posts: 24
- Joined: Thu Sep 26, 2019 1:47 pm
- Location: Leeds, UK
Re: Make JSON
Still same issue, although I notice another warning message os spaces as below
ERROR - Spaces are not allowed in variable definition in 'JSON code'
ERROR - JSON code failed SyntaxError: Unexpected token X in JSON at position 67
This is the start of the JSON Code
{
"items": [
{
"orderReference": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/Job/JobNo"]",
"recipient": {
"address": {
"fullName": "[Database.Text:SQL="SELECT DeliveryContact FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"companyName": "[Database.Text:SQL="SELECT DeliveryCustomerName FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine1": "[Database.Text:SQL="SELECT DeliveryAddress FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine2": "",
"addressLine3": "",
"city": "[Database.Text:SQL="SELECT DeliveryTown FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"county": "",
"postcode": "[Database.Text:SQL="SELECT DeliveryPostcode FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"countryCode": ""
},
ERROR - Spaces are not allowed in variable definition in 'JSON code'
ERROR - JSON code failed SyntaxError: Unexpected token X in JSON at position 67
This is the start of the JSON Code
{
"items": [
{
"orderReference": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/Job/JobNo"]",
"recipient": {
"address": {
"fullName": "[Database.Text:SQL="SELECT DeliveryContact FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"companyName": "[Database.Text:SQL="SELECT DeliveryCustomerName FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine1": "[Database.Text:SQL="SELECT DeliveryAddress FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine2": "",
"addressLine3": "",
"city": "[Database.Text:SQL="SELECT DeliveryTown FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"county": "",
"postcode": "[Database.Text:SQL="SELECT DeliveryPostcode FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"countryCode": ""
},
Re: Make JSON
the error you got is from parsing the JSON
The Switch variables must be in single quotes for Switch to add the value
Try it this way, note the single quote around the variable
Those single quotes will be replaced by the app before parsing and validation.
The Switch variables must be in single quotes for Switch to add the value
Code: Select all
"orderReference": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/Job/JobNo"]"
Code: Select all
"orderReference": '[Metadata.Text:Dataset="Xml",Model="XML",Path="/Job/JobNo"]'
-
- Member
- Posts: 24
- Joined: Thu Sep 26, 2019 1:47 pm
- Location: Leeds, UK
Re: Make JSON
Hi Jan
Still same Error
JSON code failed SyntaxError: Unexpected token X in JSON at position 67
I did change the code to:
{
"items": [
{
"orderReference": '[Metadata.Text:Dataset="Xml",Model="XML",Path="/Job/JobNo"]',
"recipient": {
"address": {
"fullName": "[Database.Text:SQL="SELECT DeliveryContact FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"companyName": "[Database.Text:SQL="SELECT DeliveryCustomerName FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine1": "[Database.Text:SQL="SELECT DeliveryAddress FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine2": "",
"addressLine3": "",
"city": "[Database.Text:SQL="SELECT DeliveryTown FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"county": "",
"postcode": "[Database.Text:SQL="SELECT DeliveryPostcode FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"countryCode": ""
},
"phoneNumber": "",
"addressBookReference": ""
},
Still same Error
JSON code failed SyntaxError: Unexpected token X in JSON at position 67
I did change the code to:
{
"items": [
{
"orderReference": '[Metadata.Text:Dataset="Xml",Model="XML",Path="/Job/JobNo"]',
"recipient": {
"address": {
"fullName": "[Database.Text:SQL="SELECT DeliveryContact FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"companyName": "[Database.Text:SQL="SELECT DeliveryCustomerName FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine1": "[Database.Text:SQL="SELECT DeliveryAddress FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"addressLine2": "",
"addressLine3": "",
"city": "[Database.Text:SQL="SELECT DeliveryTown FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"county": "",
"postcode": "[Database.Text:SQL="SELECT DeliveryPostcode FROM MainJobDetails WHERE JobNo = '[Metadata.Text:Path="/Job/JobNo",Dataset="Xml",Model="XML"]'",Connection="PRIMO"]",
"countryCode": ""
},
"phoneNumber": "",
"addressBookReference": ""
},
Re: Make JSON
You still have double quotes around the variables
Re: Make JSON
And I see that you haven't added the replacement characters like "items": #%# and the rest until #@# at the end of that array.
If you rename the app element in your flow with "debug_" at the start your JSON code will show up in the messages Debug section. This can help you sort out what is wrong in your code.
If you rename the app element in your flow with "debug_" at the start your JSON code will show up in the messages Debug section. This can help you sort out what is wrong in your code.