Csv to Json converter tool
I have a csv file which I want to convert to Avro; because there are no tools to convert directly from csv to avro, i decided to use an online tool to convert from csv to json and then I plan to write a small program to convert that json to convert to an avro model.
The problem I have is that the csv file looks like this
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
every column after H3 is part of the H3 array.
The existing tools dont seem to have this feature included (this one says it does, but im not sure how to use it: http://www.convertcsv.com/csv-to-json.htm).
Does anybody know how to deal with this.
Thanks,
Shripadsrd
json csv avro
add a comment |
I have a csv file which I want to convert to Avro; because there are no tools to convert directly from csv to avro, i decided to use an online tool to convert from csv to json and then I plan to write a small program to convert that json to convert to an avro model.
The problem I have is that the csv file looks like this
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
every column after H3 is part of the H3 array.
The existing tools dont seem to have this feature included (this one says it does, but im not sure how to use it: http://www.convertcsv.com/csv-to-json.htm).
Does anybody know how to deal with this.
Thanks,
Shripadsrd
json csv avro
Do you have any existing code that processes that csv file currently? If so where does it store the output it reads from the csv file? It may be easier to convert that output to JSON is what I am thinking.
– Ryan Vincent
Aug 19 '15 at 3:34
I dont have code to process csv, i have code to process json into avro. i was hoping to have an online tool convert csv to json for me.
– shripadsrd
Aug 19 '15 at 14:47
I am the creator of convertcsv.com and you can do this on the CSV to JSON page - 1. Paste data into text area. 2. Press the CSV to JSON button. Contact me on website for details if you need help.
– dataman
Sep 11 '15 at 0:53
I'm not clear about the question... can you provide the JSON that you expect to be outputted given the input data you provided? Something like this?{ "H1":"A1","H2":"A2","H3":["A4","A4"] }
– thdoan
Nov 3 '15 at 7:52
add a comment |
I have a csv file which I want to convert to Avro; because there are no tools to convert directly from csv to avro, i decided to use an online tool to convert from csv to json and then I plan to write a small program to convert that json to convert to an avro model.
The problem I have is that the csv file looks like this
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
every column after H3 is part of the H3 array.
The existing tools dont seem to have this feature included (this one says it does, but im not sure how to use it: http://www.convertcsv.com/csv-to-json.htm).
Does anybody know how to deal with this.
Thanks,
Shripadsrd
json csv avro
I have a csv file which I want to convert to Avro; because there are no tools to convert directly from csv to avro, i decided to use an online tool to convert from csv to json and then I plan to write a small program to convert that json to convert to an avro model.
The problem I have is that the csv file looks like this
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
every column after H3 is part of the H3 array.
The existing tools dont seem to have this feature included (this one says it does, but im not sure how to use it: http://www.convertcsv.com/csv-to-json.htm).
Does anybody know how to deal with this.
Thanks,
Shripadsrd
json csv avro
json csv avro
asked Aug 19 '15 at 3:27
shripadsrd
4616
4616
Do you have any existing code that processes that csv file currently? If so where does it store the output it reads from the csv file? It may be easier to convert that output to JSON is what I am thinking.
– Ryan Vincent
Aug 19 '15 at 3:34
I dont have code to process csv, i have code to process json into avro. i was hoping to have an online tool convert csv to json for me.
– shripadsrd
Aug 19 '15 at 14:47
I am the creator of convertcsv.com and you can do this on the CSV to JSON page - 1. Paste data into text area. 2. Press the CSV to JSON button. Contact me on website for details if you need help.
– dataman
Sep 11 '15 at 0:53
I'm not clear about the question... can you provide the JSON that you expect to be outputted given the input data you provided? Something like this?{ "H1":"A1","H2":"A2","H3":["A4","A4"] }
– thdoan
Nov 3 '15 at 7:52
add a comment |
Do you have any existing code that processes that csv file currently? If so where does it store the output it reads from the csv file? It may be easier to convert that output to JSON is what I am thinking.
– Ryan Vincent
Aug 19 '15 at 3:34
I dont have code to process csv, i have code to process json into avro. i was hoping to have an online tool convert csv to json for me.
– shripadsrd
Aug 19 '15 at 14:47
I am the creator of convertcsv.com and you can do this on the CSV to JSON page - 1. Paste data into text area. 2. Press the CSV to JSON button. Contact me on website for details if you need help.
– dataman
Sep 11 '15 at 0:53
I'm not clear about the question... can you provide the JSON that you expect to be outputted given the input data you provided? Something like this?{ "H1":"A1","H2":"A2","H3":["A4","A4"] }
– thdoan
Nov 3 '15 at 7:52
Do you have any existing code that processes that csv file currently? If so where does it store the output it reads from the csv file? It may be easier to convert that output to JSON is what I am thinking.
– Ryan Vincent
Aug 19 '15 at 3:34
Do you have any existing code that processes that csv file currently? If so where does it store the output it reads from the csv file? It may be easier to convert that output to JSON is what I am thinking.
– Ryan Vincent
Aug 19 '15 at 3:34
I dont have code to process csv, i have code to process json into avro. i was hoping to have an online tool convert csv to json for me.
– shripadsrd
Aug 19 '15 at 14:47
I dont have code to process csv, i have code to process json into avro. i was hoping to have an online tool convert csv to json for me.
– shripadsrd
Aug 19 '15 at 14:47
I am the creator of convertcsv.com and you can do this on the CSV to JSON page - 1. Paste data into text area. 2. Press the CSV to JSON button. Contact me on website for details if you need help.
– dataman
Sep 11 '15 at 0:53
I am the creator of convertcsv.com and you can do this on the CSV to JSON page - 1. Paste data into text area. 2. Press the CSV to JSON button. Contact me on website for details if you need help.
– dataman
Sep 11 '15 at 0:53
I'm not clear about the question... can you provide the JSON that you expect to be outputted given the input data you provided? Something like this?
{ "H1":"A1","H2":"A2","H3":["A4","A4"] }
– thdoan
Nov 3 '15 at 7:52
I'm not clear about the question... can you provide the JSON that you expect to be outputted given the input data you provided? Something like this?
{ "H1":"A1","H2":"A2","H3":["A4","A4"] }
– thdoan
Nov 3 '15 at 7:52
add a comment |
3 Answers
3
active
oldest
votes
What you are looking for is wrapping your JSON result based on some nesting parameters. Basically going from this :
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
To this:
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
I created a tool to solve this type of problems at http://csvtojson.com
What you need to do, is adapt your header so that it explicitly states how you want to nest your result.
For your example, it would look like :
H1, H2, H3.0, H3.1, H3.2
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
Notice how H3
is repeated using dots H3.0
, H3.1
, H3.2
: these dots represents how you want to wrap your results into an H3
array. Eventually, press the "Convert button" and your result will be prompted to you.
Hope it helps.
add a comment |
I am not familar with Avro but the following jq filter will perform the transformation
Jona Rodrigues describes. Specifically: if the file filter.jq
contains
[
split("n") # split string into lines
| (.[0] | split(",")) as $headers # split header
| (.[1:] | split(",")) # split data rows
| select(length>0) # get rid of empty lines
| $headers[:-1] as $h1 # fixed headers
| .[:($h1|length)] as $p1 # fixed part
| .[($h1|length):] as $p2 # variable part
| (
[ [ $h1, $p1 ] #
| transpose # assemble fixed object
| {key:.[0], value:.[1]} # / from fixed keys and values
] | from_entries # /
) + {
($headers[-1]): $p2 # assemble variable object
}
]
and data
contains
H1,H2,H3
A1,A2,A3,A4,A4
B1,B2,B3,B4
C1,C2,C3
then the command
jq -M -R -s -r -f filter.jq data
will produce
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
add a comment |
This can be accomplished in Powershell.
Import-Csv "foo.csv" | ConvertTo-Json | Add-Content -Path "foo.json"
You can add the -compress switch to remove newlines too
Import-Csv "foo.csv" | ConvertTo-Json -compress | Add-Content -Path "foo.json"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32086035%2fcsv-to-json-converter-tool%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
What you are looking for is wrapping your JSON result based on some nesting parameters. Basically going from this :
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
To this:
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
I created a tool to solve this type of problems at http://csvtojson.com
What you need to do, is adapt your header so that it explicitly states how you want to nest your result.
For your example, it would look like :
H1, H2, H3.0, H3.1, H3.2
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
Notice how H3
is repeated using dots H3.0
, H3.1
, H3.2
: these dots represents how you want to wrap your results into an H3
array. Eventually, press the "Convert button" and your result will be prompted to you.
Hope it helps.
add a comment |
What you are looking for is wrapping your JSON result based on some nesting parameters. Basically going from this :
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
To this:
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
I created a tool to solve this type of problems at http://csvtojson.com
What you need to do, is adapt your header so that it explicitly states how you want to nest your result.
For your example, it would look like :
H1, H2, H3.0, H3.1, H3.2
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
Notice how H3
is repeated using dots H3.0
, H3.1
, H3.2
: these dots represents how you want to wrap your results into an H3
array. Eventually, press the "Convert button" and your result will be prompted to you.
Hope it helps.
add a comment |
What you are looking for is wrapping your JSON result based on some nesting parameters. Basically going from this :
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
To this:
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
I created a tool to solve this type of problems at http://csvtojson.com
What you need to do, is adapt your header so that it explicitly states how you want to nest your result.
For your example, it would look like :
H1, H2, H3.0, H3.1, H3.2
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
Notice how H3
is repeated using dots H3.0
, H3.1
, H3.2
: these dots represents how you want to wrap your results into an H3
array. Eventually, press the "Convert button" and your result will be prompted to you.
Hope it helps.
What you are looking for is wrapping your JSON result based on some nesting parameters. Basically going from this :
H1, H2, H3
------------------
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
To this:
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
I created a tool to solve this type of problems at http://csvtojson.com
What you need to do, is adapt your header so that it explicitly states how you want to nest your result.
For your example, it would look like :
H1, H2, H3.0, H3.1, H3.2
A1, A2, A3, A4, A4
B1, B2, B3, B4
C1, C2, C3
Notice how H3
is repeated using dots H3.0
, H3.1
, H3.2
: these dots represents how you want to wrap your results into an H3
array. Eventually, press the "Convert button" and your result will be prompted to you.
Hope it helps.
answered May 3 '17 at 22:38
Jona Rodrigues
346211
346211
add a comment |
add a comment |
I am not familar with Avro but the following jq filter will perform the transformation
Jona Rodrigues describes. Specifically: if the file filter.jq
contains
[
split("n") # split string into lines
| (.[0] | split(",")) as $headers # split header
| (.[1:] | split(",")) # split data rows
| select(length>0) # get rid of empty lines
| $headers[:-1] as $h1 # fixed headers
| .[:($h1|length)] as $p1 # fixed part
| .[($h1|length):] as $p2 # variable part
| (
[ [ $h1, $p1 ] #
| transpose # assemble fixed object
| {key:.[0], value:.[1]} # / from fixed keys and values
] | from_entries # /
) + {
($headers[-1]): $p2 # assemble variable object
}
]
and data
contains
H1,H2,H3
A1,A2,A3,A4,A4
B1,B2,B3,B4
C1,C2,C3
then the command
jq -M -R -s -r -f filter.jq data
will produce
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
add a comment |
I am not familar with Avro but the following jq filter will perform the transformation
Jona Rodrigues describes. Specifically: if the file filter.jq
contains
[
split("n") # split string into lines
| (.[0] | split(",")) as $headers # split header
| (.[1:] | split(",")) # split data rows
| select(length>0) # get rid of empty lines
| $headers[:-1] as $h1 # fixed headers
| .[:($h1|length)] as $p1 # fixed part
| .[($h1|length):] as $p2 # variable part
| (
[ [ $h1, $p1 ] #
| transpose # assemble fixed object
| {key:.[0], value:.[1]} # / from fixed keys and values
] | from_entries # /
) + {
($headers[-1]): $p2 # assemble variable object
}
]
and data
contains
H1,H2,H3
A1,A2,A3,A4,A4
B1,B2,B3,B4
C1,C2,C3
then the command
jq -M -R -s -r -f filter.jq data
will produce
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
add a comment |
I am not familar with Avro but the following jq filter will perform the transformation
Jona Rodrigues describes. Specifically: if the file filter.jq
contains
[
split("n") # split string into lines
| (.[0] | split(",")) as $headers # split header
| (.[1:] | split(",")) # split data rows
| select(length>0) # get rid of empty lines
| $headers[:-1] as $h1 # fixed headers
| .[:($h1|length)] as $p1 # fixed part
| .[($h1|length):] as $p2 # variable part
| (
[ [ $h1, $p1 ] #
| transpose # assemble fixed object
| {key:.[0], value:.[1]} # / from fixed keys and values
] | from_entries # /
) + {
($headers[-1]): $p2 # assemble variable object
}
]
and data
contains
H1,H2,H3
A1,A2,A3,A4,A4
B1,B2,B3,B4
C1,C2,C3
then the command
jq -M -R -s -r -f filter.jq data
will produce
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
I am not familar with Avro but the following jq filter will perform the transformation
Jona Rodrigues describes. Specifically: if the file filter.jq
contains
[
split("n") # split string into lines
| (.[0] | split(",")) as $headers # split header
| (.[1:] | split(",")) # split data rows
| select(length>0) # get rid of empty lines
| $headers[:-1] as $h1 # fixed headers
| .[:($h1|length)] as $p1 # fixed part
| .[($h1|length):] as $p2 # variable part
| (
[ [ $h1, $p1 ] #
| transpose # assemble fixed object
| {key:.[0], value:.[1]} # / from fixed keys and values
] | from_entries # /
) + {
($headers[-1]): $p2 # assemble variable object
}
]
and data
contains
H1,H2,H3
A1,A2,A3,A4,A4
B1,B2,B3,B4
C1,C2,C3
then the command
jq -M -R -s -r -f filter.jq data
will produce
[
{
"H1": "A1",
"H2": "A2",
"H3": [
"A3",
"A4",
"A4"
]
},
{
"H1": "B1",
"H2": "B2",
"H3": [
"B3",
"B4"
]
},
{
"H1": "C1",
"H2": "C2",
"H3": [
"C3"
]
}
]
answered Sep 1 '17 at 3:58
jq170727
4,60921131
4,60921131
add a comment |
add a comment |
This can be accomplished in Powershell.
Import-Csv "foo.csv" | ConvertTo-Json | Add-Content -Path "foo.json"
You can add the -compress switch to remove newlines too
Import-Csv "foo.csv" | ConvertTo-Json -compress | Add-Content -Path "foo.json"
add a comment |
This can be accomplished in Powershell.
Import-Csv "foo.csv" | ConvertTo-Json | Add-Content -Path "foo.json"
You can add the -compress switch to remove newlines too
Import-Csv "foo.csv" | ConvertTo-Json -compress | Add-Content -Path "foo.json"
add a comment |
This can be accomplished in Powershell.
Import-Csv "foo.csv" | ConvertTo-Json | Add-Content -Path "foo.json"
You can add the -compress switch to remove newlines too
Import-Csv "foo.csv" | ConvertTo-Json -compress | Add-Content -Path "foo.json"
This can be accomplished in Powershell.
Import-Csv "foo.csv" | ConvertTo-Json | Add-Content -Path "foo.json"
You can add the -compress switch to remove newlines too
Import-Csv "foo.csv" | ConvertTo-Json -compress | Add-Content -Path "foo.json"
answered Nov 12 at 14:56
Danny Rodriguez
849
849
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32086035%2fcsv-to-json-converter-tool%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have any existing code that processes that csv file currently? If so where does it store the output it reads from the csv file? It may be easier to convert that output to JSON is what I am thinking.
– Ryan Vincent
Aug 19 '15 at 3:34
I dont have code to process csv, i have code to process json into avro. i was hoping to have an online tool convert csv to json for me.
– shripadsrd
Aug 19 '15 at 14:47
I am the creator of convertcsv.com and you can do this on the CSV to JSON page - 1. Paste data into text area. 2. Press the CSV to JSON button. Contact me on website for details if you need help.
– dataman
Sep 11 '15 at 0:53
I'm not clear about the question... can you provide the JSON that you expect to be outputted given the input data you provided? Something like this?
{ "H1":"A1","H2":"A2","H3":["A4","A4"] }
– thdoan
Nov 3 '15 at 7:52