How to correctly convert a csv to JSON for an array?

Get help using Construct 3!

Post » Tue Oct 24, 2017 4:43 am

I'm looking to convert a CSV to JSON so it can be imported into Construct 3 and then seen as an array.

I'm able to create an array with the editor and see what it looks like:
Code: Select all
{
    "c2array": true,
    "size": [
        4,
        2,
        1
    ],
    "data": [
                [
                    [
                         "bash"
                     ],
                    [
                         "charge"
                     ]
                 ],
                [
                    [
                         "take 2 damage"
                    ],
                    [
                        "take 3 damage from everyone"
                    ]
                ],
                [
                    [
                        7
            ],
            [
                9
            ]
        ],
        [
            [
                20
            ],
            [
                20
            ]
        ]
    ]
}


Unfortunately, I can't find a way to use ConvertCSV or a similar tool to get the same formatting and extent of brackets. When I use ConvertCSV, this is the closest I can get when choosing to convert it to a JSON array:

Code: Select all
{
   "c2array": true,
   "size": [9,8,1],
   "data": [
  ["Bash","Deal 3 damage to target","7",20,1,"Deal double damage.","Take 3 damage.","Melee","Attack"  ],
  ["Beserk","Next round, deal and take double damage.","8",20,1,"Deal and take quadruple damage.","Deal damage as normal, but take double damage.","Melee","Attack"  ],
  ["Blood Rage","Play one ability from your hand. Double its effects if you are at or below 1/2 health.","6",20,1,"Play the ability twice","You take double damage this round.","Melee","Draw"  ],
  ["Bloodlust","Deal 4 damage to target, where X is your health.","X",20,1,"Deal double damage.","Take 4 damage.","Melee","Attack"  ],
  ["Charge","Deal 5 damage to target.","9",20,9,"Deal double damage.","Taek 3 damage.","Melee","Attack"  ],
  ["Counter Attack","Deal damage equal to the damage you take from enemies this round (not including surge, before reductions) to target.","8",20,1,"Deal double damage.","You take double damage this round.","Melee","Attack"  ],
  ["Desperation","Deal damage equal to your maximum health minus your current health to target.","9",20,1,"Deal double damage.","You are reduced to 0 health.","Melee","Attack"  ]
]
   
}



I can see it's different, but what I use or what is Construct's format actually called?
B
20
S
6
Posts: 34
Reputation: 1,870

Post » Tue Oct 24, 2017 6:18 am

Mistakes were made.
B
62
S
30
G
134
Posts: 1,973
Reputation: 75,473

Post » Wed Oct 25, 2017 7:24 am

Awesome! You're amazing. Thank you. :D

How would I go about allowing the converter to parse commas? Currently, it just skips them and deletes whatever characters come after them in the cell.
B
20
S
6
Posts: 34
Reputation: 1,870

Post » Wed Oct 25, 2017 8:25 pm

I modified it a bit to try to account for commas within cells, but I didn't really test extensively. Give it a shot and make sure to proofread.

Note this will now completely not work for .csv files that don't encapsulate cell data in quotations.

Edit: Also will break if you have any newline breaks in cell data.
Mistakes were made.
B
62
S
30
G
134
Posts: 1,973
Reputation: 75,473

Post » Thu Oct 26, 2017 7:44 am

Awesome! Thank you again!

In case anyone needs it, here's the Google Sheet template I'm using to convert my existing data to have the quotations necessary for converting with this tool.

Also, here's the tool hosted online, so you don't have to download it, open it, and run it in C3.
B
20
S
6
Posts: 34
Reputation: 1,870


Return to How do I...?

Who is online

Users browsing this forum: Alon, trainstation and 0 guests