Forum Discussion

Parin's avatar
Parin
New Contributor
5 years ago

Create JSON from CSV file

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

    • Parin's avatar
      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's avatar
        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's avatar
    Parin
    New Contributor

    HI Supratim,

    Yes the mapper snap will work.

    Thanks,
    Parin Shah