What could cause Xojo.GenerateJSON not to generate expanded JSON?

I’m pulling my hair out trying to track down an issue with Xojo.GenerateJSON. Despite passing true to the second parameter, it gives me compact JSON. I’ve been trying to track down the issue so I can file a bug report, but I’m making no progress. Here’s some head scratchers

  • This only happens in the ARM/Universal versions on an M1 processor. Intel versions are fine.
  • A new project with the same input gives the correct result. This is true of the ARM and Universal versions of the new project.
  • Sandboxing / signing doesn’t appear to be to blame. The new project is unsigned, the existing project has been tested without signing. No change.
  • Both projects have otherwise identical build settings.
  • Even as the very first line of App.Open, the incorrect result is still generated.
  • Plugin caches have been wiped.
  • Xojo 2021r2.1 and Xojo 2021r3

My test couldn’t be simpler:

Var Members() As String = Array("One", "Two", "Three")

Var Dict As New Dictionary
Dict.Value("Key") = "Value"
Dict.Value("Number") = 1
Dict.Value("List") = Members
Dict.Value("Key With Spaces") = "Yep"

Var Result As String = Xojo.GenerateJSON(Dict, True)
Break

So now I’m at the point that I’m wondering if somebody at Xojo could please look at the code and give me some ideas of things to test. What conditions exist that could possibly make this fail?

At least this simplify the searches for Xojo.

Ok, I figured it out: feedback://showreport?report_id=66705

This one is one of the most bizarre bugs I’ve ever seen. Seems like calling GenerateJSON inside a method does not work. Events work fine, which is bizarre because events are just methods. I thought it might be the return statement for some reason, so I had the method Base64 encode the result before returning it, but the result is still wrong.

I can’t say I’ve seen anything like this before. There is a sample project attached to the case.

2 Likes

Thom, I can’t reproduce this - app compiled in 2021 R3 on macOS 11.6 (Intel), building either ARM or Universal, the built app copied to a M1 mini running Monterey 12.1 beta. Both buttons show the same result.

What is your M1 configuration? Are you building on M1? (I’m building on Intel)

This sounds like a corrupted cache of some sort. When you say “plugin caches have been wiped” - did you click the “Clear Caches” button in Xojo / Preferences / Building? I think Xojo has separate caches for Plugins and user compiled code, doesn’t it?

I deleted the entire ~/Library/Caches/Xojo and ~/Library/Caches/com.xojo.xojo folders. I just tried with no plugins at all, but the effect is the same. I have an M1 Max 64GB with 12.0.1. I did notice this time around that the test project built app works fine, but running from the IDE is where it fails. Strangely, my actual app exhibits the behavior when built.

I’m thinking this is something related to signing.

:open_mouth:

Try ditching the Dictionary and go straight to the JSONItem. I’d be curious to see if you get the same error:

Var Members() As String = Array(“One”, “Two”, “Three”)

Var j As New JSONItem
j.Value(“Key”) = “Value”
j.Value(“Number”) = 1
j.Value(“List”) = Members
j.Value(“Key With Spaces”) = “Yep”

Var Result As String = j.ToString
Break

I tried

Var JSON As New JSONItem(Dict)
JSON.Compact = False
Return JSON.ToString

But the result is the same.

When I try

Var Members As New JSONItem
Members.Add("One")
Members.Add("Two")
Members.Add("Three")

Var Dict As New JSONItem
Dict.Value("Key") = "Value"
Dict.Value("Number") = 1
Dict.Value("List") = Members
Dict.Value("Key With Spaces") = "Yep"
Dict.Compact = False

Return Dict.ToString

I again get the same result.

So JSONItem makes no difference.

You know, on my machine, I never gat any “expanded” JSON no matter what I do. Using your example and setting JSONItem.Compact=False makes no difference and passing True to GenerateJSON doesn’t either. It’s always the same 79 bytes.

Xojo 2021 r3, MacBook Pro M1, BigSur 11.4

I don’t think we’ll make any more progress on this issue without input from Xojo. Maybe somebody will chime in tomorrow.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.