cancel
Showing results for 
Search instead for 
Did you mean: 

Create JSON from CSV file

Parin
New Contributor

Hi,

I am new to snaplogic and want to create a JSON structure from a CSV file.

CSV file data
“Name”,“AddressLine1”
“Test1234”,“122 Test St”

The structure i need is very specific like:

[
{
“attributes”: {
“Name”: [
{
“value”: “Test1234”
}
],
“Addresses”: [
{
“value”: {
“AddressLine1”: [
{
“value”: “122 Test St”
}
]
}
}]
}]

Can someone help with a sample pipeline to create Json from CSV data

4 REPLIES 4

alchemiz
Contributor III

Hi Parin,

I’m not sure if my assumptions are correct attributes are group of column names right? See sample pipeline

image

canvas03_2020_09_19.slp (10.4 KB)

Parin
New Contributor

Hi Alchemiz,

Thank you for the sample snap and your assumption is correct but this is not the exact structure that i am looking for.

The different records are part of same array like in case of fname.

I have attached a smaple json for mutiple records which i need to create.

Also is there a way we can use JSON Generator snap which can use csv file data and convert it into JSON as i looking for something more dynamic.SampleJSON.txt (1.9 KB)

Supratim
Contributor III

@Parin
Use mapper snap and keep your desired structure. Only replace the hardcoded part with $ like below.Then use group by N and make group size 0 to make it as array

{
“attributes”: {
“Name”: [
{
“value”:$Name
}
],
“Addresses”: [
{
“value”: {
“AddressLine1”: [
{
“value”: $AddressLine1
}
],
“City”: [
{
“value”: “AVC”
}
],
“StateProvince”: [
{
“value”: “WV”
}
],
“Country”: [
{
“value”: “US”
}
],
“Zip5”: [
{
“value”: “25271”
}
],
“AddrBestFlag”: [
{
“value”: “Y”
}
],
“Zip4”: [
{
“value”: null
}
]
}
}
]
}
}

Parin
New Contributor

HI Supratim,

Yes the mapper snap will work.

Thanks,
Parin Shah