# Convert Sample String into JSON format

**URL:** <https://forum.uipath.com/t/convert-sample-string-into-json-format/399748>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, webapi, activities\
**Created:** [February 16, 2022, 9:39am UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748 "2022-02-16T09:39:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shantanu\_More](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shantanu_more/32/209360_2.png) [@Shantanu\_More](https://forum.uipath.com/u/Shantanu_More)\
**Post date:** [February 16, 2022, 9:39am UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/1 "2022-02-16T09:39:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![THIRU\_NANI](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/thiru_nani/32/317561_2.png) [@THIRU\_NANI](https://forum.uipath.com/u/THIRU_NANI)\
**Post date:** [February 16, 2022, 10:07am UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/2 "2022-02-16T10:07:59Z")

</div>

Hi! welcome to community!

have a view on this

> [@Put string into Json](https://forum.uipath.com/t/put-string-into-json/256644/6):
>
> Update: Much faster way to build JSON [[How to create JSON in VB.NET very fast (UiPath)] ](https://www.youtube.com/watch?v=gjca03HpZno)

Regards,  
NaNi

---

<div class="post-metadata">

**Author:** ![Shantanu\_More](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shantanu_more/32/209360_2.png) [@Shantanu\_More](https://forum.uipath.com/u/Shantanu_More)\
**Post date:** [February 16, 2022, 10:11am UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/3 "2022-02-16T10:11:18Z")

</div>

Nope, not relevant 🙂

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [February 16, 2022, 10:47am UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/4 "2022-02-16T10:47:03Z")

</div>

there are several options to construct e.g. JSON / JObject

![grafik](https://global.discourse-cdn.com/uipath/original/4X/6/c/d/6cd31530650659c6377168cd436a56de24e38bfa.png)  
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

---

<div class="post-metadata">

**Author:** ![Cristian\_Negulescu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cristian_negulescu/32/32964_2.png) [@Cristian\_Negulescu](https://forum.uipath.com/u/Cristian_Negulescu)\
**Post date:** [February 16, 2022, 11:36am UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/5 "2022-02-16T11:36:55Z")

</div>

```auto
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`

```

---

<div class="post-metadata">

**Author:** ![Shantanu\_More](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shantanu_more/32/209360_2.png) [@Shantanu\_More](https://forum.uipath.com/u/Shantanu_More)\
**Post date:** [February 22, 2022, 4:19pm UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/6 "2022-02-22T16:19:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shantanu\_More](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shantanu_more/32/209360_2.png) [@Shantanu\_More](https://forum.uipath.com/u/Shantanu_More)\
**Post date:** [February 22, 2022, 4:20pm UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/7 "2022-02-22T16:20:13Z")

</div>

Hi, Thanks for your valuable input.  
Cheers ! 🙂

Thanks,  
Shantanu

---

<div class="post-metadata">

**Author:** ![Cristian\_Negulescu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cristian_negulescu/32/32964_2.png) [@Cristian\_Negulescu](https://forum.uipath.com/u/Cristian_Negulescu)\
**Post date:** [February 22, 2022, 7:27pm UTC](https://forum.uipath.com/t/convert-sample-string-into-json-format/399748/8 "2022-02-22T19:27:39Z")

</div>

In the code, you have 4 JSON examples and 4 [VB.NET](http://VB.NET) codes that build each example. You have all stuff in this video:  
[UiPath Tutorial for JSON Parsing and Creation | 8 UseCase - YouTube](https://youtu.be/AH_4CxljnME)
