How to convert text file to json file

I am unable to convert the text file to json file. How do I do it? kindly help me to resolve this issue

1 Like

@sneha_arbole

Is your input text file contains data in json format ? May I know why you want to convert text file into JSON file ?

JSON is text.

Show us what you have and what you’re trying to do with it.

we have a text input file from which we have to extract few fields and add them to json file. i have extracted the fields but unable to convert or create json file.

1 Like

Hey @sneha_arbole

Just create a dictionary variable with key value pairs like fields as keys in dictionary and values of it.

After that, just do a json serialise which will do the job…

//Package required - Newtonsoft.Json

JsonConvert.SerializeObject(dict_Fields)

The above gives you a JSON string which can be written in a file or can be used however required.

Thanks
#nK

this is not working for me

1 Like

we can help more directly once you shared a sample file along with the expected JSON result. Thanks for support

Hey @sneha_arbole

Could you please show the steps you have tried please ?

Thanks
#nK

I had assigned the given syntax
JsonConvert.SerializeObject(dict_Fields)

1 Like

Hey @sneha_arbole

What’s the error for the above please ?

Thanks
#nK

A regex / Dict Approach:

Flow & Variables:

Results:

Find starter help here:
ppr_RegexBox_KeyValueText_ToJson.xaml (8.9 KB)

KeyValueText_ToJson.txt (163 Bytes)

We highly recommend to ensure / or to handle Unique Key issues and entries not matching the the key : value pattern