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

1 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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:

    {
        "c2array": true,
        "size": [
            4,
            2,
            1
        ],
        "data": [
                    [
                        [
                             "bash"
                         ],
                        [
                             "charge"
                         ]
                     ],
                    [
                        [
                             "take 2 damage"
                        ],
                        [
                            "take 3 damage from everyone"
                        ]
                    ],
                    [
                        [
                            7
                ],
                [
                    9
                ]
            ],
            [
                [
                    20
                ],
                [
                    20
                ]
            ]
        ]
    }[/code:2i2pe46s]
    
    Unfortunately, I can't find a way to use [url=http://www.convertcsv.com/csv-to-json.htm]ConvertCSV[/url] 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:2i2pe46s]{
       "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"  ]
    ]
       
    }
    
    [/code:2i2pe46s]
    
    I can see it's different, but what I use or what is Construct's format actually called?
  • Awesome! You're amazing. Thank you.

    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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

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