<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to convert dictionary to CDT?</title><link>https://community.appian.com/discussions/f/integrations/11669/how-to-convert-dictionary-to-cdt</link><description>Hi all, 
 I am using an Appian integration with Google Maps in which I am passing an address to get the latitude and longitude of that address. I am getting the result in dictionary format as follows: 
 
 Value 
 
 Dictionary success: true result: Dictionary</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to convert dictionary to CDT?</title><link>https://community.appian.com/thread/51407?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 05:05:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6db6a9bb-13e2-49c1-8c23-e8e46008d0c8</guid><dc:creator>Brinda</dc:creator><description>Thank you Malcom.  I will try as suggested by you.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert dictionary to CDT?</title><link>https://community.appian.com/thread/51406?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 05:04:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ad1df70f-d2e6-4cc7-a16b-192eef7f7b34</guid><dc:creator>Brinda</dc:creator><description>Thank you Benjamin.  I created an expression rule and called it in the interface where I am giving address as input.  Now I am able to get the latitude and and longitude for the given address.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert dictionary to CDT?</title><link>https://community.appian.com/thread/51405?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 00:40:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:07700ba5-2ad3-4b6a-b613-58667fd040e7</guid><dc:creator>malcolm.ross</dc:creator><description>&lt;p&gt;It would first be most efficient to run the fromJson once for your entire JSON string instead of calling it multiple times.. &lt;br /&gt; &lt;br /&gt; Like this&lt;br /&gt; &lt;br /&gt; load(&lt;br /&gt; local!googleMapsValue: a!fromJson( {your JSON string} ),&lt;br /&gt; ................&lt;br /&gt; &lt;br /&gt; Then declare a local variable of the desired CDT type using type! to create a new value of the desired CDT type&lt;br /&gt; &lt;br /&gt; &amp;#39;type!{urn:com:appian:types:{NAMESPACE}}{CDT NAME}&amp;#39;()&lt;br /&gt; &lt;br /&gt; If you are using 17.4, then you will get an autosuggest when you type type! to pick your desired CDT.&lt;br /&gt; &lt;br /&gt; Once you have your value of type declared, then start filling in the values. like&lt;br /&gt; &lt;br /&gt; load(&lt;br /&gt; local!googleMapsValue: a!fromJson( {your JSON string} ),&lt;br /&gt; local!CDTwithLatLng: &amp;#39;type!{urn:com:appian:types:{NAMESPACE}}{CDT NAME}&amp;#39;( &lt;br /&gt; &lt;br /&gt; lat: local!googleMapsValue.results.geometry.location.lat&lt;br /&gt; lng: local!googleMapsValue.results.geometry.location.lng&lt;br /&gt; ),&lt;br /&gt; &lt;br /&gt; local!CDTwithLatLng&lt;br /&gt; )&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; So essentially what you are doing is first converting the JSON to a data dictionary.&lt;br /&gt; &lt;br /&gt; Then you are extracting the values you want using . notation and placing them in the desired CDT structure by declaring the variable to be of a certain type with type!&lt;br /&gt; &lt;br /&gt; As mentioned, it is most efficient to only convert the JSON string once to data dictionary rather call fromJSON multiple times.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert dictionary to CDT?</title><link>https://community.appian.com/thread/51404?ContentTypeID=1</link><pubDate>Mon, 08 Jan 2018 00:23:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e503be61-604f-48a4-8053-80d042b72874</guid><dc:creator>benjamins</dc:creator><description>&lt;p&gt;Similar to what was described above, doing this should work:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;= with(
  local!result: rule!MY_INTEGRATION_RULE(),
  local!json: a!fromJson(local!result.result.body),
  local!lat: local!json.results.geometry.location.lat,
  local!lng: local!json.results.geometry.location.lng
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Double check the json response. Start by just printing the response and then go down a level to see if it still returns valid responses. Continue until you get all the way to the lat an lon.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You may want to check how you are passing in the rule input into your integration object.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ensure that it looks like&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;quot;https://maps.googleapis.com/maps/api/geocode/json?address=&amp;quot; &amp;amp; ri!address + &amp;quot;&amp;amp;key=&amp;lt;MY_KEY&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert dictionary to CDT?</title><link>https://community.appian.com/thread/51401?ContentTypeID=1</link><pubDate>Sun, 07 Jan 2018 13:53:37 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:649db7f7-9c3d-4bba-9532-e1a3860ab961</guid><dc:creator>Brinda</dc:creator><description>&lt;p&gt;Hi Jeromew,&lt;/p&gt;
&lt;p&gt;In the integration I am using &amp;nbsp;&amp;quot;GET&amp;quot; method and using parameters to pass address and key. &amp;nbsp;I am not using body in my inputs.&lt;/p&gt;
&lt;p&gt;But I am getting the result in dictionary. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffffff;"&gt;When I try to change the result into JSON by using the code suggested by you, it is throwing an error as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffff00;"&gt;Expression evaluation error at function a!fromJson [line 9]: Error evaluating function fn!fromjson_appian_internal : The jsonText parameter must not be null or empty.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ffffff;"&gt;Kindly let me know why I am getting the error and how can get the latitude and longitude?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to convert dictionary to CDT?</title><link>https://community.appian.com/thread/51396?ContentTypeID=1</link><pubDate>Sat, 06 Jan 2018 21:36:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ecf07c6d-9845-41b5-baa6-5599d0a8a19c</guid><dc:creator>jeromew</dc:creator><description>Hi Brinda,&lt;br /&gt;
&lt;br /&gt;
You should be able to extract the information like this:&lt;br /&gt;
&lt;br /&gt;
  /* change the result into JSON and get the relevant result body*/&lt;br /&gt;
  local!lat: a!fromJson({your variable}.body.results.geometry.location.lat),&lt;br /&gt;
  local!lng: a!fromJson({your variable}response.body.results.geometry.location.lng)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>