HttpService:JSONEncode producing invalid JSON

What it’s producing:

[null,{"admin":{"Charm{\"id\":\"Royalty\",\"tn\":1}":1}},{"Fishing":{"":1},"StairwayToHeaven":{"":1}},{"Fishing":{"":6.2666709423065189},"StairwayToHeaven":{"":6.2336671352386479}}]

The correct json (ignore the fact that it’s prettyprinted)

{
  "2": {
    "admin": {
      "Charm{\"id\":\"Royalty\",\"tn\":1}": 1
    }
  },
  "3": {
    "Fishing": {
      "": 1
    },
    "StairwayToHeaven": {
      "": 1
    }
  },
  "4": {
    "Fishing": {
      "": 6.2666709423065186
    },
    "StairwayToHeaven": {
      "": 6.2336671352386475
    }
  }
}

data is defined in lua as:

local queue: {[number]: {[string]: {[string]: number}}} = {}

It’s incorrectly treating the table as an array.

From what I know, this has always been the behavior, or rather it is inherently flaky.

If you want your queue to serialize with string numbers, then you should call tostring on the keys before passing them into JSONEncode.

Is this a recent regression?

I don’t know if it’s a recent regression however in my own JSON encoder this issue is not present because I check if it’s an array by inspecting length. However I will adjust the code to work with string to avoid this issue. Thank you!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.