R2Northstar / NorthstarLauncher

Launcher used to modify Titanfall 2 to allow mods to be loaded
MIT License
281 stars 126 forks source link

JSON parsing doesn't support top level arrays #421

Open ASpoonPlaysGames opened 1 year ago

ASpoonPlaysGames commented 1 year ago

Json files do not have to be an object (table). They can be just an array, which we don't (and can't) handle atm because we return a table instead of a var

This usecase of JSON is perfectly valid, and Juicy (who I cant seem to @ ) has already ran into this problem grabbing data from speedrun.com

If anyone else is looking for the solution to this in the future, (in script) you can use string concatenation to encapsulate the JSON array in an object and then you can parse it into a table with the normal JSON functions

string jsonArray = "[\"foo\", \"bar\"]" // result from elsewhere, currently cannot be parsed into a table
jsonArray = "{ \"data\": " + jsonArray + "}" // encapsulate the array in an object
// the array data can now be parsed and used

This should be fixed, but should probably be done in a separate PR

_Originally posted by @ASpoonPlaysGames in https://github.com/R2Northstar/NorthstarLauncher/pull/404#discussion_r1113702357_

uniboi commented 1 year ago

Wouldn't changing the signature to var break any mod that uses the function?

ASpoonPlaysGames commented 1 year ago

Yes

uniboi commented 1 year ago

could just leave it and do expect array( DecodeJSON( json ) ) :trollface:

BigSpice commented 1 year ago

❤️