Hi, I need to convert following sample string into JSON format. What could be easiest and best solution? Any help would be appreciated.
String e.g.
Test Data :
Test 1 : Data 1,
Test 2 : Data 2,
Test 3 : Data 3
@supermanPunch @Palaniyappan . Have your tried this? Convert normal string into JSON format?
Thanks,
Shantanu
Hi! welcome to community!
have a view on this
Regards,
NaNi
ppr
(Peter Preuss)
4
there are several options to construct e.g. JSON / JObject

Protoype is doing this with:
- JProperty Arrays
- Dictionary Serialization
Test 1 : Data 1,
Test 2 : Data 2,
Test 3 : Data 3
Processing the text we can do:
- split function on Line break and :
- send the token into the generation of JProperties, Dictionary
Another option could also be to use regex and enrich the text to a JSON
JSON1
{
"name": "Jeff",
"id": 1,
"car": "BMW"
}
VB.NET1
JObject.FromObject(
New With {
key .name = "Jeff",
key .id = 1,
key .car = "BMW"
}
).ToString
JSON2
{
"name": "John",
"id": 5,
"car": "BMW",
"photo":{
"height": 200,
"witdh": 100
}
}
VB.NET2
JObject.FromObject(
New With {
key .name = "John",
key .id = 5,
key .car = "BMW",
key .photo = New With{
key .height = 200,
key .witdh = 100
}
}
).ToString
JSON3
{
"records":
[
{
"name": "John",
"id": 1
},
{
"name": "Tim",
"id": 2
},
{
"name": "Jeff",
"id": 3
}
]
}
VB.NET3
JObject.FromObject(
New With {
key .name = "John",
key .id = 1
}
)
.....
JObject.FromObject(
New With {
key .records = JArray.FromObject(list)
}
).ToString
JSON4
{
"records":
[
{
"name": "John",
"id": 1,
"cars": ["BMW","AUDI","HONDA"]
},
{
"name": "Tim",
"id": 2,
"cars": ["VW","SEAT","SKODA"]
},
{
"name": "Jeff",
"id": 3,
"cars": ["TOYOTA","MAZDA"]
}
]
}
VB.NET4
JObject.FromObject(
New With {
key .name = "John",
key .id = 1,
key .cars = New String() {"BMW","AUDI","HONDA"}
}
)
.....
JObject.FromObject(
New With {
key .records = JArray.FromObject(list)
}
).ToString`Preformatted text`
Hi, Sorry, I did not get you.
Could you please elaborate?
I’m able to resolve the issue using split function and got the relevant result.
But looking for more robust solution.
It would be great but you could provide more insight.
Thanks,
Shantanu
Hi, Thanks for your valuable input.
Cheers ! 
Thanks,
Shantanu
In the code, you have 4 JSON examples and 4 VB.NET codes that build each example. You have all stuff in this video:
UiPath Tutorial for JSON Parsing and Creation | 8 UseCase - YouTube