JSON Syntax Errors

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
7 Errors
$15 USD
7 Errors is a game where you have to find the 7 mistakes before time runs out. Can you find all 7? Have fun looking.
  • Hey guys! First time trying to create C3 plugin and having issues with JSON input in action parameters. When I try to enter this JSON in an action parameter field:

    [{"key":"username","value":"JohnDoe"},{"key":"email","value":"test@example.com"}]

    I get syntax errors at certain characters like:

    The opening bracket [ The @ symbol in email addresses Commas , between objects Is there a proper way to handle JSON input in plugin action parameters? Or do I need to use a different approach for complex data input? My plugin accepts a string parameter that should contain a JSON array, but Construct 3's parameter system seems to have issues with these special characters. any advice on best practices for handling structured data input in plugin actions? tried escaped string format too but same. Maybe I'll just pass it as variable? :/

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Construct only understands numbers, strings and booleans. You need to quote the whole thing to pass it as a string.

    '[{"key":"username","value":"JohnDoe"},{"key":"email","value":"test@example.com"}]'

    In your plugin code you can then use JSON.parse(your_string) to transform the JSON string into a JSON object.

    About quotes... make sure the outermost quotes are different to the ones used in the JSON object. In this case I quoted the whole thing in single quotes, that way the computer can easily understand that everything in between the single quotes should be a string.

    If for some reason you wanted to use double quotes in the outermost layer, you would need to escape the double quotes in the JSON string so they are interpreted as the raw character instead of their special meaning and it would look something like this

    "[{\"key\":\"username\",\"value\":\"JohnDoe\"},{\"key\":\"email\",\"value\":\"test@example.com\"}]"
    

    In my opinion you should only do something like that if it's absolutely necessary.

  • Construct only understands numbers, strings and booleans. You need to quote the whole thing to pass it as a string.

    > '[{"key":"username","value":"JohnDoe"},{"key":"email","value":"test@example.com"}]'

    In your plugin code you can then use JSON.parse(your_string) to transform the JSON string into a JSON object.

    About quotes... make sure the outermost quotes are different to the ones used in the JSON object. In this case I quoted the whole thing in single quotes, that way the computer can easily understand that everything in between the single quotes should be a string.

    If for some reason you wanted to use double quotes in the outermost layer, you would need to escape the double quotes in the JSON string so they are interpreted as the raw character instead of their special meaning and it would look something like this

    > "[{\"key\":\"username\",\"value\":\"JohnDoe\"},{\"key\":\"email\",\"value\":\"test@example.com\"}]"
    

    In my opinion you should only do something like that if it's absolutely necessary.

    Appreciate your help Diego thank you very much!

  • My advice is to add a JSON project file and load it with AJAX. Then you can use a dedicated editor for your JSON data without having to worry about how to properly escape JSON strings in expressions, which is quite fiddly.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)