How do I take this CSV make it JSON & load into an Array

Get help using Construct 3!

Post » Fri Jul 21, 2017 5:16 pm

Hey Everyone,
I'm trying to import a large csv (deliminated by commas) into my game with the ability to change global variables to values located in the array.

Some questions:
What is the exact format of the JSON file does it need to be in? I've seen things about tweaking the format of standard JOSN
Anyone have a good source to convert CSV to JSON?

Thank you!
Bryan
B
4
Posts: 20
Reputation: 240

Post » Fri Jul 21, 2017 7:02 pm

For a 3D array you want your JSON in this format:

{
"c2array":true,
"size":[2,3,4],
"data":[

[ [0,1,2,3], [4,5,6,7], [8,9,10,11] ],

[ [12,13,14,15], [16,17,18,19 ], [20,21,22,23] ]

]
}

For 2D like this:

{
"c2array":true,
"size":[2,3,1],
"data":[

[ [0], [1], [2] ],

[ [3], [4], [5] ]

]
}
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

Post » Sat Jul 22, 2017 1:01 am

Thank you very much! This format works for what i want to do, i just don't know the easiest way to convert a standard csv to this format without manually editing it.

mekonbekon wrote:For a 3D array you want your JSON in this format:

{
"c2array":true,
"size":[2,3,4],
"data":[

[ [0,1,2,3], [4,5,6,7], [8,9,10,11] ],

[ [12,13,14,15], [16,17,18,19 ], [20,21,22,23] ]

]
}

For 2D like this:

{
"c2array":true,
"size":[2,3,1],
"data":[

[ [0], [1], [2] ],

[ [3], [4], [5] ]

]
}
B
4
Posts: 20
Reputation: 240

Post » Sat Jul 22, 2017 10:27 am

This tool gets you close, if you choose CSV to JSON array in step 5:

http://www.convertcsv.com/csv-to-json.htm

Annoyingly it doesn't add sets of brackets around each y value, but on the plus side you can add double quotes in step 3, if you're using strings.
You might be able to use the custom options in step 4 to get exactly what you need, haven't tried it out yet.
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

Post » Sat Jul 22, 2017 10:57 am

Rex's CSV2Array plugin may help you, but it is only available for C2, as far as I'm aware. plugin-csv-csv2array-csv2dictionary_t64326
B
32
S
7
G
4
Posts: 397
Reputation: 4,589


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 1 guest