Convert CSV to JSON - challenge

Seems my coding brain has gone on holiday...:upside_down_face:

I have a solution, but feel certain there is a better way to do this.

The requirement is to convert a standard csv to json format:

CSV

id,name,email
1,john,john@gmail.com
2,sue,sue@gmail.com
3,bob,bob@gmail.com
4,nick,nick@gmail.com

to

JSON

[
	{
		"id":"1",
		"name":"john",
		"email":"john@gmail.com"
	},
	{
		"id":"2",
		"name":"sue",
		"email":"sue@gmail.com"
	},
	{
		"id":"3",
		"name":"bob",
		"email":"bob@gmail.com"
	},
	{
		"id":"4",
		"name":"nick",
		"email":"nick@gmail.com"
	}
]

I have these blocks that do it:

and an aia project

csvToJson.aia (3.2 KB)

Probably a simpler approach, with a dozen less blocks.

Works on the condition that there are at least two rows (including the header) and at least one column.

image

Is this correct?

2 Likes