How can I create a Entity from a Json file ?

I am getting location data (lat, lon) via json and want to add markers and polylines with it . I was thinking of converting it into entity so that i can make its aggregate and use those values for adding marker and polylines .


kindly tell me about this . also if there is another way to do it  I would love to know 

mvp_badge
MVP
Solution

Hi Pratik,

I see what your problem is. Indeed, JSON Deserialize wants a Text, and like all Text, in OutSystems this means that you need to enclose it in double quotes. The error message you got was Service Studio complaining, in a somewhat obfuscated way, that it didn't understand the input, as a Text input can be a variable, function or string literal, and what you copy/pasted is neither.

That said, you can't just put double quotes around it either, as the string literal itself contains double quotes. The website you used to convert it converts them to \", but OutSystems needs double double quotes in this case, so "" for every ". So in order to test your JSON Deserialize, you need a different format. Find attached an example that should work, if copy/pasted as a string literal in OutSystems.

Of course, you'd normally not use string literals for JSON data, but receive the data from a file or REST service etc., so I don't think you would normally encounter this problem.

JSON literal.txt

1. You need to deserialize the json into correct data type. 

2. your json is now is in a local variable (list of record), you need to iterate (loop) each of record before saving to entity...

Hello @Pratik Giri,

Kind of similar query explained in below forum post link.

Please find the below link for your query.

How to load JSON file's data into an entity 


Regards,

Narendra Bhangale.

Hi ,

You can use JSON Deserialize  https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Traditional_Web/Web_Logic_Tools/JSON_Deserialize  to convert JSON to record list and you can easily store JSON data to entity.

In case you don't see these JSON functions, try to open any Client Actions or Server Actions and you will see them on the left side.

thank you the deserialize worked but i am getting a error can you please help me with it .

so i imported json in Structure  via add Structure  from json . now i got the Structure called it jsontrying 


now used json deserialize and passed stringfy version of my json to it and gave data type jsontrying 


but i am a error that says \  is an unexpected token

Screenshot (42).png

mvp_badge
MVP

In addition to the above answers, the context menu of the Structure folder on the data tab allows you to create a structure from JSON. This saves manual adding of every attribute.

thank you the deserialize worked but i am getting a error can you please help me with it .

so i imported json in Structure  via add Structure  from json . now i got the Structure called it jsontrying 


now used json deserialize and passed stringfy version of my json to it and gave data type jsontrying 


but i am a error that says \  is an unexpected token

Screenshot (42).png

mvp_badge
MVP

Hi Pratik,

It's difficult to say what the problem is without having the actual JSON. But since it complains about position 1, you should be able to check what the problem might be? I wouldn't expect a \ either at the start of a JSON text.

can i share the json with you that i converted into string or original one ?

mvp_badge
MVP

JSON is text, so I'm not sure what you converted? Anyway, please share both, so it might be possible to see what goes wrong.

I have Javascript object in json file . so I thought i should convert it in string . 


json file (original) : 

{
"Dataset 1":[
 {
  "Order ID": 1180031124,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Hard Rock CAFE",
  "Estimate Arrival Time": "04/20/2022 10:00:00 am",
  "Estimate DepartureTime": "4/20/2022 10:05:00 am",
  "Latitude": 12.99189,
  "Longitude": 80.21726
 },
 {
  "Order ID": 1140377771,
  "Restaurant Type": "American Food",
  "Restaurant Name": "QT Grills",
  "Estimate Arrival Time": "4/20/2022 10:30:00 am",
  "Estimate DepartureTime": "4/20/2022 10:35:00 am",
  "Latitude": 13.00681,
  "Longitude": 80.25364
 },
 {
  "Order ID": 1140377780,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Sizzlers",
  "Estimate Arrival Time": "04/20/2022 11:00:00 am",
  "Estimate DepartureTime": "4/20/2022 11:05:00 am",
  "Latitude": 13.0673,
  "Longitude": 80.22747
 },
 {
  "Order ID": 1180030614,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Double Roti",
  "Estimate Arrival Time": "4/20/2022 11:30:00 am",
  "Estimate DepartureTime": "4/20/2022 11:35:00 am",
  "Latitude": 12.95641,
  "Longitude": 80.25536
 },
 {
  "Order ID": 1180030514,
  "Restaurant Type": "American Food",
  "Restaurant Name": "TGI Friday's",
  "Estimate Arrival Time": "04/20/2022 12:00:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:05:00 pm",
  "Latitude": 13.04309,
  "Longitude": 80.2479
 },
 {
  "Order ID": 1180034798,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Chennai Wing House",
  "Estimate Arrival Time": "4/20/2022 12:30:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:35:00 pm",
  "Latitude": 12.8373,
  "Longitude": 80.22869
 }
],
"Dataset 2":[
 {
  "Order ID": 1140368959,
  "Restaurant Type": "Seafood",
  "Restaurant Name": "Ammachi Chettinadu",
  "Estimate Arrival Time": "4/21/2022 9:00:00 am",
  "Estimate DepartureTime": "4/21/2022 9:10:00 am",
  "Latitude": 13.08517,
  "Longitude": 80.20333
 },
 {
  "Order ID": 1180035705,
  "Restaurant Type": "Seafood",
  "Restaurant Name": "SKS Sea Foods",
  "Estimate Arrival Time": "4/21/2022 9:45:00 am",
  "Estimate DepartureTime": "4/21/2022 9:55:00 am",
  "Latitude": 12.97024,
  "Longitude": 80.24513
 },
 {
  "Order ID": 1149544054,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Justin's Sandwich",
  "Estimate Arrival Time": "4/21/2022 10:30:00 am",
  "Estimate DepartureTime": "4/21/2022 10:40:00 am",
  "Latitude": 13.04186,
  "Longitude": 80.17616
 },
 {
  "Order ID": 1180031188,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Tuck Shop Gourmet",
  "Estimate Arrival Time": "4/21/2022 11:15:00 am",
  "Estimate DepartureTime": "4/21/2022 11:25:00 am",
  "Latitude": 13.07329,
  "Longitude": 80.26087
 },
 {
  "Order ID": 1180029769,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Chick Blast",
  "Estimate Arrival Time": "4/21/2022 12:00:00 pm",
  "Estimate DepartureTime": "4/21/2022 12:10:00 pm",
  "Latitude": 12.92363,
  "Longitude": 80.14281
 },
 {
  "Order ID": 1140371977,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Nik & Nacks",
  "Estimate Arrival Time": "4/21/2022 12:45:00 pm",
  "Estimate DepartureTime": "4/21/2022 12:55:00 pm",
  "Latitude": 12.92518,
  "Longitude": 80.14766
 },
 {
  "Order ID": 1123047482,
  "Restaurant Type": "Vegetarian Food",
  "Restaurant Name": "Mani Iyer Cafe",
  "Estimate Arrival Time": "4/21/2022 1:30:00 pm",
  "Estimate DepartureTime": "4/21/2022 1:40:00 pm",
  "Latitude": 13.04118,
  "Longitude": 80.21573
 }
],
"Dataset 3":[
 {
  "Order ID": 1083514351,
  "Restaurant Type": "Vegetarian Food",
  "Restaurant Name": "Matta",
  "Estimate Arrival Time": "4/20/2022 12:00:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:01:00 pm",
  "Latitude": 13.03731,
  "Longitude": 80.2133
 },
 {
  "Order ID": 1178772081,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Slappy Joes",
  "Estimate Arrival Time": "4/20/2022 12:10:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:11:00 pm",
  "Latitude": 13.06439,
  "Longitude": 80.23717
 },
 {
  "Order ID": 1180030658,
  "Restaurant Type": "Japanese Food",
  "Restaurant Name": "Cheong Ki Wa",
  "Estimate Arrival Time": "4/20/2022 12:20:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:21:00 pm",
  "Latitude": 13.04963,
  "Longitude": 80.25518
 },
 {
  "Order ID": 1136302026,
  "Restaurant Type": "Japanese Food",
  "Restaurant Name": "Suwon Kalbhi",
  "Estimate Arrival Time": "4/20/2022 12:30:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:31:00 pm",
  "Latitude": 13.00771,
  "Longitude": 80.25321
 },
 {
  "Order ID": 1140377267,
  "Restaurant Type": "Japanese Food",
  "Restaurant Name": "Pure",
  "Estimate Arrival Time": "4/20/2022 12:40:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:41:00 pm",
  "Latitude": 13.00483,
  "Longitude": 80.25724
 },
 {
  "Order ID": 1191760472,
  "Restaurant Type": "Japanese Food",
  "Restaurant Name": "Sora Jima-the Accord Metropolitan",
  "Estimate Arrival Time": "4/20/2022 12:50:00 pm",
  "Estimate DepartureTime": "4/20/2022 12:51:00 pm",
  "Latitude": 13.04619,
  "Longitude": 80.24237
 }
],
"Dataset 4":[
 {
  "Order ID": 1140377771,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Arasampatti",
  "Estimate Arrival Time": "4/21/2022 9:00:00 am",
  "Estimate DepartureTime": "4/21/2022 9:05:00 am",
  "Latitude": 12.92974,
  "Longitude": 80.11871
 },
 {
  "Order ID": 1140377780,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Hottentots",
  "Estimate Arrival Time": "4/21/2022 10:00:00 am",
  "Estimate DepartureTime": "4/21/2022 10:05:00 am",
  "Latitude": 12.94409,
  "Longitude": 80.12079
 },
 {
  "Order ID": 1180030614,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Brick House Bistro",
  "Estimate Arrival Time": "4/21/2022 11:00:00 am",
  "Estimate DepartureTime": "4/21/2022 11:05:00 am",
  "Latitude": 13.09246,
  "Longitude": 80.21165
 },
 {
  "Order ID": 1180030514,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Hoppipola-the Spring",
  "Estimate Arrival Time": "4/21/2022 12:00:00 pm",
  "Estimate DepartureTime": "4/21/2022 12:05:00 pm",
  "Latitude": 13.05264,
  "Longitude": 80.24866
 },
 {
  "Order ID": 1180034798,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Toastie Express",
  "Estimate Arrival Time": "4/21/2022 1:00:00 pm",
  "Estimate DepartureTime": "4/21/2022 1:05:00 pm",
  "Latitude": 13.05813,
  "Longitude": 80.26432
 },
 {
  "Order ID": 1152884118,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Gazebo",
  "Estimate Arrival Time": "4/21/2022 2:00:00 pm",
  "Estimate DepartureTime": "4/21/2022 2:05:00 pm",
  "Latitude": 12.84128,
  "Longitude": 80.15473
 },
 {
  "Order ID": 1069509565,
  "Restaurant Type": "American Food",
  "Restaurant Name": "Sizzlers",
  "Estimate Arrival Time": "4/21/2022 3:00:00 pm",
  "Estimate DepartureTime": "4/21/2022 3:05:00 pm",
  "Latitude": 13.07343,
  "Longitude": 80.22105
 }
]
}





string converted version : 

"{\"Dataset1\":[{\"OrderID\":1180031124,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"HardRockCAFE\",\"EstimateArrivalTime\":\"04/20/202210:00:00am\",\"EstimateDepartureTime\":\"4/20/202210:05:00am\",\"Latitude\":12.99189,\"Longitude\":80.21726},{\"OrderID\":1140377771,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"QTGrills\",\"EstimateArrivalTime\":\"4/20/202210:30:00am\",\"EstimateDepartureTime\":\"4/20/202210:35:00am\",\"Latitude\":13.00681,\"Longitude\":80.25364},{\"OrderID\":1140377780,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Sizzlers\",\"EstimateArrivalTime\":\"04/20/202211:00:00am\",\"EstimateDepartureTime\":\"4/20/202211:05:00am\",\"Latitude\":13.0673,\"Longitude\":80.22747},{\"OrderID\":1180030614,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"DoubleRoti\",\"EstimateArrivalTime\":\"4/20/202211:30:00am\",\"EstimateDepartureTime\":\"4/20/202211:35:00am\",\"Latitude\":12.95641,\"Longitude\":80.25536},{\"OrderID\":1180030514,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"TGIFriday's\",\"EstimateArrivalTime\":\"04/20/202212:00:00pm\",\"EstimateDepartureTime\":\"4/20/202212:05:00pm\",\"Latitude\":13.04309,\"Longitude\":80.2479},{\"OrderID\":1180034798,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"ChennaiWingHouse\",\"EstimateArrivalTime\":\"4/20/202212:30:00pm\",\"EstimateDepartureTime\":\"4/20/202212:35:00pm\",\"Latitude\":12.8373,\"Longitude\":80.22869}],\"Dataset2\":[{\"OrderID\":1140368959,\"RestaurantType\":\"Seafood\",\"RestaurantName\":\"AmmachiChettinadu\",\"EstimateArrivalTime\":\"4/21/20229:00:00am\",\"EstimateDepartureTime\":\"4/21/20229:10:00am\",\"Latitude\":13.08517,\"Longitude\":80.20333},{\"OrderID\":1180035705,\"RestaurantType\":\"Seafood\",\"RestaurantName\":\"SKSSeaFoods\",\"EstimateArrivalTime\":\"4/21/20229:45:00am\",\"EstimateDepartureTime\":\"4/21/20229:55:00am\",\"Latitude\":12.97024,\"Longitude\":80.24513},{\"OrderID\":1149544054,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Justin'sSandwich\",\"EstimateArrivalTime\":\"4/21/202210:30:00am\",\"EstimateDepartureTime\":\"4/21/202210:40:00am\",\"Latitude\":13.04186,\"Longitude\":80.17616},{\"OrderID\":1180031188,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"TuckShopGourmet\",\"EstimateArrivalTime\":\"4/21/202211:15:00am\",\"EstimateDepartureTime\":\"4/21/202211:25:00am\",\"Latitude\":13.07329,\"Longitude\":80.26087},{\"OrderID\":1180029769,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"ChickBlast\",\"EstimateArrivalTime\":\"4/21/202212:00:00pm\",\"EstimateDepartureTime\":\"4/21/202212:10:00pm\",\"Latitude\":12.92363,\"Longitude\":80.14281},{\"OrderID\":1140371977,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Nik&Nacks\",\"EstimateArrivalTime\":\"4/21/202212:45:00pm\",\"EstimateDepartureTime\":\"4/21/202212:55:00pm\",\"Latitude\":12.92518,\"Longitude\":80.14766},{\"OrderID\":1123047482,\"RestaurantType\":\"VegetarianFood\",\"RestaurantName\":\"ManiIyerCafe\",\"EstimateArrivalTime\":\"4/21/20221:30:00pm\",\"EstimateDepartureTime\":\"4/21/20221:40:00pm\",\"Latitude\":13.04118,\"Longitude\":80.21573}],\"Dataset3\":[{\"OrderID\":1083514351,\"RestaurantType\":\"VegetarianFood\",\"RestaurantName\":\"Matta\",\"EstimateArrivalTime\":\"4/20/202212:00:00pm\",\"EstimateDepartureTime\":\"4/20/202212:01:00pm\",\"Latitude\":13.03731,\"Longitude\":80.2133},{\"OrderID\":1178772081,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"SlappyJoes\",\"EstimateArrivalTime\":\"4/20/202212:10:00pm\",\"EstimateDepartureTime\":\"4/20/202212:11:00pm\",\"Latitude\":13.06439,\"Longitude\":80.23717},{\"OrderID\":1180030658,\"RestaurantType\":\"JapaneseFood\",\"RestaurantName\":\"CheongKiWa\",\"EstimateArrivalTime\":\"4/20/202212:20:00pm\",\"EstimateDepartureTime\":\"4/20/202212:21:00pm\",\"Latitude\":13.04963,\"Longitude\":80.25518},{\"OrderID\":1136302026,\"RestaurantType\":\"JapaneseFood\",\"RestaurantName\":\"SuwonKalbhi\",\"EstimateArrivalTime\":\"4/20/202212:30:00pm\",\"EstimateDepartureTime\":\"4/20/202212:31:00pm\",\"Latitude\":13.00771,\"Longitude\":80.25321},{\"OrderID\":1140377267,\"RestaurantType\":\"JapaneseFood\",\"RestaurantName\":\"Pure\",\"EstimateArrivalTime\":\"4/20/202212:40:00pm\",\"EstimateDepartureTime\":\"4/20/202212:41:00pm\",\"Latitude\":13.00483,\"Longitude\":80.25724},{\"OrderID\":1191760472,\"RestaurantType\":\"JapaneseFood\",\"RestaurantName\":\"SoraJima-theAccordMetropolitan\",\"EstimateArrivalTime\":\"4/20/202212:50:00pm\",\"EstimateDepartureTime\":\"4/20/202212:51:00pm\",\"Latitude\":13.04619,\"Longitude\":80.24237}],\"Dataset4\":[{\"OrderID\":1140377771,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Arasampatti\",\"EstimateArrivalTime\":\"4/21/20229:00:00am\",\"EstimateDepartureTime\":\"4/21/20229:05:00am\",\"Latitude\":12.92974,\"Longitude\":80.11871},{\"OrderID\":1140377780,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Hottentots\",\"EstimateArrivalTime\":\"4/21/202210:00:00am\",\"EstimateDepartureTime\":\"4/21/202210:05:00am\",\"Latitude\":12.94409,\"Longitude\":80.12079},{\"OrderID\":1180030614,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"BrickHouseBistro\",\"EstimateArrivalTime\":\"4/21/202211:00:00am\",\"EstimateDepartureTime\":\"4/21/202211:05:00am\",\"Latitude\":13.09246,\"Longitude\":80.21165},{\"OrderID\":1180030514,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Hoppipola-theSpring\",\"EstimateArrivalTime\":\"4/21/202212:00:00pm\",\"EstimateDepartureTime\":\"4/21/202212:05:00pm\",\"Latitude\":13.05264,\"Longitude\":80.24866},{\"OrderID\":1180034798,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"ToastieExpress\",\"EstimateArrivalTime\":\"4/21/20221:00:00pm\",\"EstimateDepartureTime\":\"4/21/20221:05:00pm\",\"Latitude\":13.05813,\"Longitude\":80.26432},{\"OrderID\":1152884118,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Gazebo\",\"EstimateArrivalTime\":\"4/21/20222:00:00pm\",\"EstimateDepartureTime\":\"4/21/20222:05:00pm\",\"Latitude\":12.84128,\"Longitude\":80.15473},{\"OrderID\":1069509565,\"RestaurantType\":\"AmericanFood\",\"RestaurantName\":\"Sizzlers\",\"EstimateArrivalTime\":\"4/21/20223:00:00pm\",\"EstimateDepartureTime\":\"4/21/20223:05:00pm\",\"Latitude\":13.07343,\"Longitude\":80.22105}]}"



mvp_badge
MVP

Yeah, that "string converted" version is very wrong. It escapes all the quotes with a backslash, which makes it invalid JSON. So what did you use to convert the original JSON to the "string" version? And why did you do that in the first place? You should just feed the original JSON into the JSON Deserialize.

When I give original json I get error shown below in image . now when i hover over json string in json deserialize it wants data type of text . so I thought i should convert it into a string . I converted it from this website : https://jsontostring.com/ .  

Screenshot (58).png

mvp_badge
MVP
Solution

Hi Pratik,

I see what your problem is. Indeed, JSON Deserialize wants a Text, and like all Text, in OutSystems this means that you need to enclose it in double quotes. The error message you got was Service Studio complaining, in a somewhat obfuscated way, that it didn't understand the input, as a Text input can be a variable, function or string literal, and what you copy/pasted is neither.

That said, you can't just put double quotes around it either, as the string literal itself contains double quotes. The website you used to convert it converts them to \", but OutSystems needs double double quotes in this case, so "" for every ". So in order to test your JSON Deserialize, you need a different format. Find attached an example that should work, if copy/pasted as a string literal in OutSystems.

Of course, you'd normally not use string literals for JSON data, but receive the data from a file or REST service etc., so I don't think you would normally encounter this problem.

JSON literal.txt

after giving the json you provided in json string of json deserialize. I got another error shown in below  image

Screenshot (64).png

mvp_badge
MVP

That's a weird error, I've never seen it before. However, it seems to be confused about the structure of the JSON vs. the Structure you used. Are you sure you specified the right Structure in the Data Type Property? See attached an example I created using the JSON you specified in your previous post. I got no errors.

TestJson.oml

I had my structure as a list .i took it as a list because of this post : https://www.outsystems.com/forums/discussion/71057/failed-to-deserialize-json/

 . thats why it wasn't working . i fixed it and everything works perfectly now . Thank you very much for helping me . as newbie i was exploring stuff and was kinda lost but thanks to you i have reached my goal .once again thank you 

mvp_badge
MVP

You are most welcome! A new Platform can indeed be a bit daunting when you just start, so I'm glad I could help you connect some dots. In general, when deserializing JSON, the Data Type you specifiy must exactly match the JSON in structure, so if the JSON is an array, you need a List, but if the JSON is an object, you need a structure variable.

If you found any of my posts the answer you were looking for, please mark them as Solution, thanks!

Thank you for giving me the tip on json deserialize . yes I'll mark it as solution

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.