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