Let’s say we have a file (*.csv, *.txt …) like :
Name, Surname, Age, Occupation
Gino, DiNanni, 19, student
Anna, Kournikova, 27, programmer
(I added those spaces just to make it readable here)
I’m trying to create a JSON (BTW it’s valid) like:
[
{
"gino_dinanni": [
{
"age": "19",
"occupation": "student",
}
]
},
{
"anna_kournikova": [
{
"age": "27",
"occupation": "programmer",
}
]
}
]
accessible like e.g.
anna_kournikova.age // 27
So far I have this http://jsbin.com/apapey/2/edit but this is giving me (awfully):
[["Age:19","Occupation:student"],["Age:27","Occupation:programmer"]]
I know how to use .toLowerCase() to create anna_kournikova and stuff, but I’m really lost in creating the right JSON “object”. I would paste some better examples I tried before, but I erased them all in a fit of rage, now going back from scratch and I need your advice. Might be I’m missing a simple detail? Thanks so much!
If you are able to change the markup of your JSON, this would yield better results,
That way you can use
data.anna_kournikova.age. As other users have suggested, your CSV should be parsed on the server side and you can just usejQuery.getJSON( ... )to retrieve it