Asset description can return invalid JSON

This should only apply to this API:
https://api.roblox.com/marketplace/productinfo?assetId=
(which might be deprecated, not really sure)

Ran into this issue when I was writing a bot that would request this API and parse the JSON:

https://api.roblox.com/marketplace/productinfo?assetId=282459910

JSON.parse: bad control character in string literal at line 1 column 123 of the JSON data

Seems to happen whenever the description contains a newline, I think there are other control characters you can do (like tabs) which break most JSON parsers.

1 Like

I see "a\nb", which is a valid JSON string value. I am surprised parsers don’t handle this properly.

Maybe your transformation of the result to string already converts \, n into a single character - newline?

JSON.parse('"a\nb"') -> SyntaxError
JSON.parse('"a\\nb"') -> OK

What parser & language are you using?

1 Like

I’m using node.js with a library called phin which has an option to automatically parse JSON for requests. It was giving me trouble a couple of days ago by failing to parse it.

For reference this was the URL it was erroring on:
https://api.roblox.com/marketplace/productinfo?assetId=2603216737

It doesn’t seem to be doing it anymore though. I’m kinda confused. I tested with both request-promise and phin and used JSON.parse and It’s working correctly now.

EDIT: I delved deeper into the situation by using a bare bones request module. I have concluded that it is not the fact the JSON is invalid, but that API has the chance to return a non-JSON error message:

This id failed:  337208324
This is the web response:  The custom error module does not recognize this error.
This was the error:  SyntaxError: Unexpected token T in JSON at position 0
    at JSON.parse (<anonymous>)
    at getSalesFromAssetIds (C:\Users\Jacob\Downloads\clothing-express(1)\clothing-express\api\catalog.js:50:29)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.getTotalSalesFromId (C:\Users\Jacob\Downloads\clothing-express(1)\clothing-express\api\catalog.js:66:22)
    at async Promise.all (index 0)
    at async C:\Users\Jacob\Downloads\clothing-express(1)\clothing-express\main.js:25:30

The custom error module does not recognize this error. is the culprit here, no idea why the API returns that sometimes - I am requesting it extremely fast so that could be the issue why.

Yeah that seems to be the case, the status code is 429 - Too many requests.