<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use .NET to convert JSON via AutoLISP in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9386421#M20094</link>
    <description>&lt;P&gt;I thaught that returning an association list was closer to the Json object structure (key-value pairs), and the access to data can be done with the classical: (cdr (assoc key)).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The attached assembly defines two LISP functions &lt;STRONG&gt;json-&amp;gt;list&lt;/STRONG&gt; (same as previous) and &lt;STRONG&gt;json-&amp;gt;alist.&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(setq str
       "{ \"prop1\":\"val1\",
       \"prop2\":123.4,
       \"prop3\":[
         { \"a\":null,\"b\":true },
         { \"c\":1234,\"d\":false }
       ]
     }"
)&lt;/LI-CODE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;_$ (json-&amp;gt;list str)
("prop1" "val1" "prop2" 123.4 "prop3" (("a" nil "b" T) ("c" 1234 "d" nil)))

_$ (json-&amp;gt;alist str)
(("prop1" . "val1")
  ("prop2" . 123.4)
  ("prop3" (("a") ("b" . T)) (("c" . 1234) ("d")))
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C# code for the &lt;STRONG&gt;json-&amp;gt;alist&lt;/STRONG&gt; function:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [LispFunction("JSON-&amp;gt;AList")]
        public static ResultBuffer JasonToAssocList(ResultBuffer resbuf)
        {
            if (resbuf == null)
                return null;
            var args = resbuf.AsArray();
            if (args.Length != 1)
                return null;
            if (args[0].TypeCode != (int)LispDataType.Text)
                return null;
            string arg = (string)args[0].Value;
            try
            {
                var dict = new JavaScriptSerializer().DeserializeObject(arg)
                    as Dictionary&amp;lt;string, dynamic&amp;gt;;
                var result = new ResultBuffer();
                AddDictionary(result, dict);
                return result;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(
                    $"Error: {ex.Message}");
                return null;
            }
        }

        private static void AddDictionary(ResultBuffer result, Dictionary&amp;lt;string, dynamic&amp;gt; dict)
        {
            foreach (var pair in dict)
            {
                result.Add(new TypedValue((int)LispDataType.ListBegin));
                result.Add(new TypedValue((int)LispDataType.Text, pair.Key));
                switch (pair.Value)
                {
                    case null:
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case string s:
                        result.Add(new TypedValue((int)LispDataType.Text, s));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case int i:
                        result.Add(new TypedValue((int)LispDataType.Int32, i));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case decimal d:
                        result.Add(new TypedValue((int)LispDataType.Double, d));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case bool b when !b:
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case bool b when b:
                        result.Add(new TypedValue((int)LispDataType.T_atom));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case Dictionary&amp;lt;string, object&amp;gt; d:
                        result.Add(new TypedValue((int)LispDataType.ListBegin));
                        AddDictionary(result, d);
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case object[] a:
                        foreach (var o in a) AddValue(result, o);
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    default:
                        break;
                }
            }
        }

        private static void AddValue(ResultBuffer result, object obj)
        {
            switch (obj)
            {
                case null:
                    result.Add(new TypedValue((int)LispDataType.Nil));
                    break;
                case string s:
                    result.Add(new TypedValue((int)LispDataType.Text, s));
                    break;
                case int i:
                    result.Add(new TypedValue((int)LispDataType.Int32, i));
                    break;
                case decimal d:
                    result.Add(new TypedValue((int)LispDataType.Double, d));
                    break;
                case bool b when !b:
                    result.Add(new TypedValue((int)LispDataType.Nil));
                    break;
                case bool b when b:
                    result.Add(new TypedValue((int)LispDataType.T_atom));
                    break;
                case Dictionary&amp;lt;string, object&amp;gt; d:
                    result.Add(new TypedValue((int)LispDataType.ListBegin));
                    AddDictionary(result, d);
                    result.Add(new TypedValue((int)LispDataType.ListEnd));
                    break;
                case object[] a:
                    result.Add(new TypedValue((int)LispDataType.ListBegin));
                    foreach (var o in a) AddValue(result, o);
                    result.Add(new TypedValue((int)LispDataType.ListEnd));
                    break;
                default:
                    break;
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Mar 2020 06:52:32 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2020-03-19T06:52:32Z</dc:date>
    <item>
      <title>Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9382709#M20085</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand it's a faux pas to ask for a product without perhaps some existing code, but I hope my example can serve you well enough as I am not savvy enough with .NET to get off in the right direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I know it's possible to create AutoLISP functions via .NET (&lt;A href="https://subscription.packtpub.com/book/application_development/9781849699372/1/ch01lvl1sec17/using-net-with-autolisp-become-an-expert" target="_blank" rel="noopener"&gt;Example HERE&lt;/A&gt;), I was wondering if perhaps anyone has or could provide a method to convert a JSON&amp;nbsp;&lt;STRONG&gt;string&lt;/STRONG&gt; to its equivalent&amp;nbsp;&lt;STRONG&gt;list&lt;/STRONG&gt; counterpart (an AutoLISP list). I am not concerned with a 100% parser, since I only want to convert JSON to a List, not vice-versa.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of an input/output:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(setq str
  "{ \"prop1\":\"val1\",
     \"prop2\":123.4,
     \"prop3\":{
        [ \"a\":null,\"b\":true ],
        [ \"c\":1234,\"d\":false ]
     }
   }")
(JSON-&amp;gt;List str)
...
JSON-&amp;gt;List would return EITHER:
("prop1" "val1" "prop2" 123.4 "prop3" (("a" nil "b" t) ("c" 1234 "d" nil)))
..or..
("prop1" "val1" "prop2" 123.4 "prop3" (("a" NULL "b" t) ("c" 1234 "d" nil)))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand the general workflow in .NET. It could even be recursive, but I do not understand enough to manipulate a JSON string in .NET nor how to convert back to a LispDataType.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am asking for a .dll to do this because my product is already 99% written in AutoLISP.&lt;/P&gt;&lt;P&gt;I have tried to create a JSON-&amp;gt;List function in AutoLISP/VisualLISP but it's cumbersome,inefficient, and generally slow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help / input / guidance / advice on the matter is appreciated.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 15:12:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9382709#M20085</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2020-03-17T15:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9382935#M20086</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why doing it with .NET if LISP is the goal?&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(defun jason2list (str / strSubstAll)
  (defun strSubstAll (newStr pattern str / i)
    (setq i 0)
    (while (setq i (vl-string-search pattern str i))
      (setq str (vl-string-subst newStr pattern str i))
    )
  )
  (read
    (vl-string-translate
      "{}[]:,"
      "()()  "
      (strSubstAll
	"nil"
	"null"
	(strSubstAll
	  "nil"
	  "false"
	  (strSubstAll "T" "true" str)
	)
      )
    )
  )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 16:58:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9382935#M20086</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-17T16:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9383051#M20087</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;I did not mention, but I have been using this method and have reached its limitations which is why I am now asking for something better.&lt;/P&gt;&lt;P&gt;The &lt;A href="http://help.autodesk.com/view/ACD/2017/ENU/?guid=GUID-5B50BB3E-C244-46E8-85D8-6A2D48B1FE51" target="_blank" rel="noopener"&gt;(read ...)&lt;/A&gt; function actually has a maximum symbol length of 2305 characters. This can be demonstrated with the following function:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(defun c:TEST ( / x cnt)
  (setq x "" cnt 0)
  (while t
    (prompt (strcat "\n" (itoa (setq cnt (1+ cnt)))))
    (setq x (strcat x "x"))
    (read x)
  );while
);defun&lt;/LI-CODE&gt;&lt;P&gt;You will see that when the 2306th character is added then an error occurs and it will no longer function.&lt;/P&gt;&lt;P&gt;While I understand that CONTINUOUS strings of 2305+ characters are not very common, they still occur and interrupt my program. Unless there is another efficient method you can think of that overcomes this 2305 character limit?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 17:31:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9383051#M20087</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2020-03-17T17:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9383409#M20088</link>
      <description>&lt;P&gt;Here's a way (probably not the most efficient).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using System.Text.RegularExpressions;

namespace JasonToAutoLisp
{
    public class LispFunctions
    {
        /*
        (setq str
          "{ \"prop1\":\"val1\",
             \"prop2\":123.4,
             \"prop3\":{
                [ \"a\":null,\"b\":true ],
                [ \"c\":1234,\"d\":false ]
             }
           }")
        (JSON-&amp;gt;List str)
        */

        [LispFunction("JSON-&amp;gt;List")]
        public static ResultBuffer JasonToList(ResultBuffer resbuf)
        {
            if (resbuf == null)
                return null;
            var args = resbuf.AsArray();
            if (args.Length != 1)
                return null;
            if (args[0].TypeCode != (int)LispDataType.Text)
                return null;
            string arg = (string)args[0].Value;
            var result = new ResultBuffer();
            foreach (var str in Regex.Split(Regex.Replace(Regex.Replace(arg, @"\s+", ""), @"(\{|\[|]|})", ":$1:"), @":|,"))
            {
                switch (str)
                {
                    case string s when string.IsNullOrWhiteSpace(s):
                        break;
                    case string s when s == "{" || s == "[":
                        result.Add(new TypedValue((int)LispDataType.ListBegin));
                        break;
                    case string s when s == "}" || s == "]":
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case string s when s == "true":
                        result.Add(new TypedValue((int)LispDataType.T_atom));
                        break;
                    case string s when s == "false" || s == "null":
                        result.Add(new TypedValue((int)LispDataType.Nil));
                        break;
                    case string s when int.TryParse(s, out int i):
                        result.Add(new TypedValue((int)LispDataType.Int32, i));
                        break;
                    case string s when double.TryParse(s, out double d):
                        result.Add(new TypedValue((int)LispDataType.Double, d));
                        break;
                    default:
                        result.Add(new TypedValue((int)LispDataType.Text, str.Trim('"')));
                        break;
                }
            }
            return result;
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached the DLL to NETLOAD (do not forget to unblock the ZIP).&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:33:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9383409#M20088</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-17T20:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9384486#M20089</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for a solution to test. I get an error when trying to NETLOAD your solution.&lt;/P&gt;&lt;P&gt;I saved the .dll to my desktop and also have that path in my 'Trusted Locations'.&lt;/P&gt;&lt;P&gt;I do not currently have the ability to compile a solution myself. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Command: NETLOAD
Cannot load assembly. Error details: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\.....\Desktop\JasonToAutoLisp.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\.....\Desktop\JasonToAutoLisp.dll' ---&amp;gt; System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp;amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp;amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark&amp;amp; stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
   at loadmgd()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 11:52:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9384486#M20089</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2020-03-18T11:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9384561#M20090</link>
      <description>&lt;P&gt;you have to "Unblock" the ZIP or DLL (right click &amp;gt; Properties &amp;gt; General &amp;gt; Unblock).&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 12:30:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9384561#M20090</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-18T12:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9384657#M20091</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, I had never done that before. I got it to load and use.&lt;/P&gt;&lt;P&gt;There appears to be a problem with the regex that is being implemented.&lt;/P&gt;&lt;P&gt;My response has these characters within a string value in the JSON response "{" "}" "[" "]" ":".&lt;/P&gt;&lt;P&gt;It appears that your regex is creating lists of these values also. Is there a way to &lt;STRONG&gt;NOT&lt;/STRONG&gt; implement the regex expression to text characters &lt;STRONG&gt;inside&lt;/STRONG&gt; of a string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached an example of the JSON response I receive, so you can test with it also (if you're still up for the challenge). It is a Google Directions API response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand my initial request can be a bit cumbersome. I hate being needy, I just don't have the current means to accomplish something like this myself. If you do not wish to help further, then I understand. You have provided me with a great deal of information with your initial code response and perhaps one day I can finish this work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again. Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 13:13:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9384657#M20091</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2020-03-18T13:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9385611#M20092</link>
      <description>&lt;P&gt;I tried a new attempt using a Jason deserializer and recursion toconvert the generated dictionary into LISP lists.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

using System.Collections.Generic;
using System.Web.Script.Serialization;

namespace JasonToAutoLisp
{
    public class LispFunctions
    {
        [LispFunction("JSON-&amp;gt;List")]
        public static ResultBuffer JasonToLisp(ResultBuffer resbuf)
        {
            if (resbuf == null)
                return null;
            var args = resbuf.AsArray();
            if (args.Length != 1)
                return null;
            if (args[0].TypeCode != (int)LispDataType.Text)
                return null;
            string arg = (string)args[0].Value;
            try
            {
                var dict = new JavaScriptSerializer().DeserializeObject(arg)
                    as Dictionary&amp;lt;string, dynamic&amp;gt;;
                var result = new ResultBuffer();
                FillBuffer(dict, result);
                return result;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(
                    $"Error: {ex.Message}");
                return null;
            }
        }

        private static void FillBuffer(Dictionary&amp;lt;string, dynamic&amp;gt; pairs, ResultBuffer result)
        {
            foreach (var pair in pairs)
            {
                result.Add(new TypedValue((int)LispDataType.Text, pair.Key));
                var obj = pair.Value;
                AddValue(result, pair.Value);
            }
        }

        private static void AddValue(ResultBuffer result, dynamic obj)
        {
            switch (obj)
            {
                case null:
                    result.Add(new TypedValue((int)LispDataType.Nil));
                    break;
                case string s:
                    result.Add(new TypedValue((int)LispDataType.Text, s));
                    break;
                case int i:
                    result.Add(new TypedValue((int)LispDataType.Int32, i));
                    break;
                case decimal d:
                    result.Add(new TypedValue((int)LispDataType.Double, d));
                    break;
                case bool b when !b:
                    result.Add(new TypedValue((int)LispDataType.Nil));
                    break;
                case bool b when b:
                    result.Add(new TypedValue((int)LispDataType.T_atom));
                    break;
                case Dictionary&amp;lt;string, object&amp;gt; d:
                    result.Add(new TypedValue((int)LispDataType.ListBegin));
                    FillBuffer(d, result);
                    result.Add(new TypedValue((int)LispDataType.ListEnd));
                    break;
                case object[] a:
                    result.Add(new TypedValue((int)LispDataType.ListBegin));
                    foreach (var o in a)
                        AddValue(result, o);
                    result.Add(new TypedValue((int)LispDataType.ListEnd));
                    break;
                default:
                    break;
            }
        }
    }
}&lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 20:08:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9385611#M20092</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-18T20:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9386325#M20093</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've done limited testing, but it's working great. Thank you VERY much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;~DD&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 05:06:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9386325#M20093</guid>
      <dc:creator>CodeDing</dc:creator>
      <dc:date>2020-03-19T05:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Use .NET to convert JSON via AutoLISP</title>
      <link>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9386421#M20094</link>
      <description>&lt;P&gt;I thaught that returning an association list was closer to the Json object structure (key-value pairs), and the access to data can be done with the classical: (cdr (assoc key)).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The attached assembly defines two LISP functions &lt;STRONG&gt;json-&amp;gt;list&lt;/STRONG&gt; (same as previous) and &lt;STRONG&gt;json-&amp;gt;alist.&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(setq str
       "{ \"prop1\":\"val1\",
       \"prop2\":123.4,
       \"prop3\":[
         { \"a\":null,\"b\":true },
         { \"c\":1234,\"d\":false }
       ]
     }"
)&lt;/LI-CODE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;_$ (json-&amp;gt;list str)
("prop1" "val1" "prop2" 123.4 "prop3" (("a" nil "b" T) ("c" 1234 "d" nil)))

_$ (json-&amp;gt;alist str)
(("prop1" . "val1")
  ("prop2" . 123.4)
  ("prop3" (("a") ("b" . T)) (("c" . 1234) ("d")))
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C# code for the &lt;STRONG&gt;json-&amp;gt;alist&lt;/STRONG&gt; function:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        [LispFunction("JSON-&amp;gt;AList")]
        public static ResultBuffer JasonToAssocList(ResultBuffer resbuf)
        {
            if (resbuf == null)
                return null;
            var args = resbuf.AsArray();
            if (args.Length != 1)
                return null;
            if (args[0].TypeCode != (int)LispDataType.Text)
                return null;
            string arg = (string)args[0].Value;
            try
            {
                var dict = new JavaScriptSerializer().DeserializeObject(arg)
                    as Dictionary&amp;lt;string, dynamic&amp;gt;;
                var result = new ResultBuffer();
                AddDictionary(result, dict);
                return result;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(
                    $"Error: {ex.Message}");
                return null;
            }
        }

        private static void AddDictionary(ResultBuffer result, Dictionary&amp;lt;string, dynamic&amp;gt; dict)
        {
            foreach (var pair in dict)
            {
                result.Add(new TypedValue((int)LispDataType.ListBegin));
                result.Add(new TypedValue((int)LispDataType.Text, pair.Key));
                switch (pair.Value)
                {
                    case null:
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case string s:
                        result.Add(new TypedValue((int)LispDataType.Text, s));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case int i:
                        result.Add(new TypedValue((int)LispDataType.Int32, i));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case decimal d:
                        result.Add(new TypedValue((int)LispDataType.Double, d));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case bool b when !b:
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case bool b when b:
                        result.Add(new TypedValue((int)LispDataType.T_atom));
                        result.Add(new TypedValue((int)LispDataType.DottedPair));
                        break;
                    case Dictionary&amp;lt;string, object&amp;gt; d:
                        result.Add(new TypedValue((int)LispDataType.ListBegin));
                        AddDictionary(result, d);
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    case object[] a:
                        foreach (var o in a) AddValue(result, o);
                        result.Add(new TypedValue((int)LispDataType.ListEnd));
                        break;
                    default:
                        break;
                }
            }
        }

        private static void AddValue(ResultBuffer result, object obj)
        {
            switch (obj)
            {
                case null:
                    result.Add(new TypedValue((int)LispDataType.Nil));
                    break;
                case string s:
                    result.Add(new TypedValue((int)LispDataType.Text, s));
                    break;
                case int i:
                    result.Add(new TypedValue((int)LispDataType.Int32, i));
                    break;
                case decimal d:
                    result.Add(new TypedValue((int)LispDataType.Double, d));
                    break;
                case bool b when !b:
                    result.Add(new TypedValue((int)LispDataType.Nil));
                    break;
                case bool b when b:
                    result.Add(new TypedValue((int)LispDataType.T_atom));
                    break;
                case Dictionary&amp;lt;string, object&amp;gt; d:
                    result.Add(new TypedValue((int)LispDataType.ListBegin));
                    AddDictionary(result, d);
                    result.Add(new TypedValue((int)LispDataType.ListEnd));
                    break;
                case object[] a:
                    result.Add(new TypedValue((int)LispDataType.ListBegin));
                    foreach (var o in a) AddValue(result, o);
                    result.Add(new TypedValue((int)LispDataType.ListEnd));
                    break;
                default:
                    break;
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 06:52:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/use-net-to-convert-json-via-autolisp/m-p/9386421#M20094</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-03-19T06:52:32Z</dc:date>
    </item>
  </channel>
</rss>

