JSON.stringify not working in BASIC

I’ve noticed this problem a couple of times when trying to stringify Json string in Basic.
The only workaround I’ve found has been to switch to javascript, here’s a short sample:

Dim JsonGeo={"homeMobileCountryCode": 310, "homeMobileNetworkCode": 410, "radioType": "gsm", "carrier": "Vodafone", "considerIp": "true","cellTowers": [{"cellId": 29315071, "locationAreaCode": 20200, "mobileCountryCode": 228, "mobileNetworkCode": 2, "signalStrength": -68}]}
Dim HEREgsm = {"gsm": [{"mcc": 262,"mnc": 1,"lac": 5126,"cid": 16504, "rxLevel": -75}]}

Function MakeString()
  Try
    Dim Link = JSON.stringify(JsonGeo)
    console.log("JsonGeo: " + Link)
  Catch err
    console.log("Error with JsonGeo: " + err)
  End Try
    
  Try
    Dim Link = JSON.stringify(HEREgsm)
    console.log("HEREgsm: " + Link)
  Catch err
    console.log("Error with HEREgsm: " + err)
  End Try
        
  JavaScript
    var jsonStr=JSON.stringify(JsonGeo);
    console.log("JsonGeo: " + jsonStr)
    
    jsonStr=JSON.stringify(HEREgsm);
    console.log("HEREgsm: " + jsonStr)
  End JavaScript

End Function

Here’s what it says in the docs about the DIM statement:

“An optional initial value can also be supplied. This must be a simple variable, not an expression.”

If you do the Dim statement first, then assign the value, you should be fine.

Makes no difference, in Basic it always throws an error in the console like:
Error with JsonGeo: RangeError: Invalid array length

While the same variable, with or without a separate Dim statement, perfectly works with the Javascript stringify function

Here’s what I put into my BASIC code window:

Dim JsonGeo
Dim HEREgsm
JsonGeo={"homeMobileCountryCode": 310, "homeMobileNetworkCode": 410, "radioType": "gsm", "carrier": "Vodafone", "considerIp": "true","cellTowers": [{"cellId": 29315071, "locationAreaCode": 20200, "mobileCountryCode": 228, "mobileNetworkCode": 2, "signalStrength": -68}]}
HEREgsm = {"gsm": [{"mcc": 262,"mnc": 1,"lac": 5126,"cid": 16504, "rxLevel": -75}]}

Seems to work OK for me.

I’m still getting the errors in Basic, only the javascript version works:

Error with JsonGeo: RangeError: Invalid array length
Error with HEREgsm: RangeError: Invalid array length
JsonGeo: {"homeMobileCountryCode":310,"homeMobileNetworkCode":410,"radioType":"gsm","carrier":"Vodafone","considerIp":"true","cellTowers":[{"cellId":29315071,"locationAreaCode":20200,"mobileCountryCode":228,"mobileNetworkCode":2,"signalStrength":-68}]}
HEREgsm: {"gsm":[{"mcc":262,"mnc":1,"lac":5126,"cid":16504,"rxLevel":-75}]}

Have you tried doing this in a fresh project? Maybe the problem lies elsewhere.

Yes, the error shows up even in an empty project, like the one attached, with just a button:
TestJson.appstudio.zip (8.5 KB)

Try removing the Dim inside the Try block.

 Try
    Link = JSON.stringify(JsonGeo)
    console.log("JsonGeo: " + Link)
  Catch err
    console.log("Error with JsonGeo: " + err)
  End Try
    
  Try
    Link = JSON.stringify(HEREgsm)
    console.log("HEREgsm: " + Link)
  Catch err
    console.log("Error with HEREgsm: " + err)
  End Try