-1

I have a CSV which looks like this:

CSV

When I convert it to JSON I get this:

{
 "Thing1": "Value1",
 "Thing2": "Value2",
 "Thing3": 2209,
 "": 2210,
 ... etc

}

What I want is for it to look like this:

{
 "Thing1": "Value1",
 "Thing2": "Value2",
 "Thing3": { 
   2209,
   2210,
   2210,
   ... etc
 }
}

Do I need to write a script to make this? Thanks

mortb
  • 9,361
  • 3
  • 26
  • 44
dylankbuckley
  • 1,507
  • 1
  • 13
  • 21

3 Answers3

1

Basically, in your example, what you are looking for is to wrap a cross table into a normal json array.

I created a tiny free app at csvtojson.com that is able to convert your csv to json while allowing you to declare a nesting structure.

Following with your example, you just need to specify your output structure in your CSV header as follow:

Thing 1, Thing 2, Thing 3.0, Thing 3.1, Thing 3.2, Thing 3.3, Thing 3.4
Value 1, Value 2, 2209, 2210, 2211, 2212, 2213, 2214

Put this csv into the app and press the "Convert !" button. It will understand that Thing 3.1 is actually the second element of the array Thing 3 : exactly what you asked for.

Hope it helps !

Jona Rodrigues
  • 992
  • 1
  • 11
  • 23
0

"Thing3" should be array, then you can make well json object. it is like this

"Thing3": [] {"2209","2210"}
Damith Asanka
  • 934
  • 10
  • 12
0

There are some tools you can try without writing code, for example this popped up on a quick Google search. It claims that it supports conversion to JSON arrays which you'll need for your example (Thing3 should probably be an array) - caveat: I haven't tried it.

As you can imagine, most answers from Stackers will involve some form of programming. If you want to delve deeper there's a good example in this thread.

Last point, your example isn't strictly CSV. Perhaps you meant that the source CSV was like:

Thing1, Thing2, Thing3, Thing3, Thing3 Value1, Value2, 2209, 2210, 2211

Good luck!

Community
  • 1
  • 1
Chris McCauley
  • 25,824
  • 8
  • 48
  • 65