cancel
Showing results for 
Search instead for 
Did you mean: 

How to add data type

Pretty
New Contributor III

We have Json file as input source which some random data for that values we need to add datatypes.

Sample data:

{
“Id”: “1076”,
“jobTitle”: “Software engineer”,
“firstName”: “David”,
“lastName”: “villey”,
“fullName”: “Davidvilley”,
“email_N”: “Davidvilley@gmail.com”,
“telephoneNumber”: “+1-8474987109”
}

Please help me to add the datatypes for above data to validate.

9 REPLIES 9

Pretty
New Contributor III

@koryknick @darshthakkar @ljupcho_machkovski

Here exactly I am working on ,

We have data in json file.

{
“Id”: “1076”,
“jobTitle”: “Software engineer”,
“firstName”: “David”,
“lastName”: “villey”,
“fullName”: “Davidvilley”,
“email_N”: “Davidvilley@gmail.com”,
“telephoneNumber”: “+1-8474987109”
}

those are the data which I mentioned above,

firstly we will import this data from json file , But here we don’t have any datatype for this data so I need to add datatypes, from adding the datatype I can validate the data.

For example If we add the datatype for firstName as string(4) in this case If we pass 5 character ex:David It should through an error. I need to store this error msg in separate output so to get this result i am trying to add the datatypes.

I hope this make sense.

Thanks in advance.

Agreed, you can use a mapper for conversion to integer, string (fieldname.toString())

Pretty
New Contributor III

@darshthakkar @koryknick

Noted

Thank you for your response

koryknick
Employee
Employee

There is a Data Validator snap in the Flow snap pack, which is Public so you have access to it. As I stated, JSON supports a limited set of data types and does not restrict length or precision, so the Data Validator is probably your best bet.

alchemiz
Contributor III

Hi @Pretty

Good day… 😀

See: https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1438183/Global+Functions+and+Properties#Gl...

{
    "Id": 1076,
    "this_is_an_array": [1, 2, 3, 4, 88],
    "this_is_an_object": {
        "key": "val"
    },
    "jobTitle": "Software engineer",
    "firstName": "David",
    "lastName": "villey",
    "fullName": "Davidvilley",
    "email_N": "Davidvilley@gmail.com",
    "telephoneNumber": "+1-8474987109",
    "this_is_a_boolean": true
}.mapValues((val, key) => {'type': val}.mapKeys((v, k) => typeof v))

This outputs the type as keyname

image

Hope this helps

Thanks,
EmEm