How to output a JSON formatted array similar to this...?

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi community,

    I have a question regarding the native JSON object in C3.

    I am currently building a quiz game and need to write/output the results in a JSON formatted array or (JSON nested array) just like the example below. The JSON tutorial is extremely simple and does not cover JSON arrays. Can someone in the community guide me through the right events/actions on how to set up this structure in JSON. Is the JSON object able to to output something like this Ashley or Nepeo?

    Thank you in advanced for your help.

    [ { "answer": 0, "incorrect": 0, "correct": 0 }, { "answer": 0, "incorrect": 0, "correct": 0 }, { "answer": 0, "incorrect": 0, "correct": 0 }, { "answer": 0, "incorrect": 0, "correct": 0 } ]


  • I'm not very experienced with JSON, so there may be an easier way to do this, but here is my attempt:


    EDIT: wow, this is my 5000th post! :)

  • It's a little awkward because most of the actions set a value on a parent, which makes it hard to replace the root object. So there's kinda 2 ways forward, depending on what restrictions you have on the format:

    1. Easy option: keep the root as a JSONObject and place the array into a field like so:

    		"array": [
    			{ "answer": 0, "incorrect": 0, "correct": 0 },
    			{ "answer": 0, "incorrect": 0, "correct": 0 },
    			{ "answer": 0, "incorrect": 0, "correct": 0 }

    2. Hard option: Use the "parse" action to replace the root with an array, increase the size of the array using the "push value" action with dummy values, then replace those dummy values with objects using the "set object" action.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you both dop2000 and Nepeo for your input,

    I actually learned a lot from both your examples. I ended up using the hard option as explained by Nepeo as I needed to replace the root with an array and this method seemed the cleanest to use.

    Thanks again for the help.

  • Animate glad I could help, the "hard" option isn't really that hard I guess. When I was working it out it just seemed to be more complicated I guess, so long as you understand it!

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