Mapping CSV to array of objects

Tagged: ,

This topic has 0 replies, 1 voice, and was last updated 2 years, 10 months ago by XavierForde.

  • Author
    Posts
  • #26595
     XavierForde
    Participant

    Hello,

    I have created a new property in managed/Users which is an array of objects as follows.

    "addressesArrayObject" : {
                            "title" : "Array of Address Objects",
                            "type" : "array",
                            "viewable" : true,
                            "searchable" : false,
                            "userEditable" : true,
                            "items" : {
                                "type" : "object",
                                "properties" : {
                                    "post_code" : {
                                        "title" : null,
                                        "type" : "string",
                                        "viewable" : true,
                                        "searchable" : true,
                                        "userEditable" : true
                                    },
                                    "city" : {
                                        "title" : null,
                                        "type" : "string",
                                        "viewable" : true,
                                        "searchable" : true,
                                        "userEditable" : true
                                    }
                                },
                                "order" : [
                                    "post_code",
                                    "city"
                                ],
                                "required" : [ ]
                            },
                            "description" : null,
                            "isVirtual" : false
                        },

    So the the property is an array of address objects which have the properties ‘post_code’ and ‘city’. In the CSV file I have one user and the address is a string stored as follows (quoteCharaceter = ‘):
    ‘{“post_code”:”LU4TTT”,”city”:”Lyon”};{“post_code”:”PA4LTT”,”city”:”Paris”}’

    So far I can load this into an array of two JSON strings using the JS code to transform to an array:
    source.split(";")
    I am unsuccessful in trying to do the next step of creating array of objects. The CSV JSON string keys are the same as defined in the schema so I though it may be as simple as the following JS code:
    source.split(";").map(x => JSON.parse(x))

    Here is the sync.json code for the mapping to the Array of strings (which works) and the Array of objects (doesn’t work):

                    {
                        "target" : "addressesArray",
                        "transform" : {
                            "type" : "text/javascript",
                            "globals" : { },
                            "source" : "source.split(\";\")"
                        },
                        "source" : "addresslist"
                    },
                    {
                        "target" : "addressesArrayObject",
                        "source" : "addresslist",
                        "transform" : {
                            "type" : "text/javascript",
                            "globals" : { },
                            "source" : "source.split(\";\").map(x => JSON.parse(x))"
                        }
                    }

    I realise this is a basic question but I’ve been struggling to find mapping to an object for a while now. Any help greatly appreciated :)

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

©2022 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?