<div dir="ltr">It occured to me that the reason the JSON package does not define a method that generates JSON from an arbitrary object is that it does not want to assume that including the value of every instance variable is what you want. So it requires you to implement the instance method <font face="monospace">jsonWriteOn:</font>` in each of your custom classes that need to be converted to a JSON string. I think you also need to implement a class method in each of those custom classes that takes a JSON string and returns an object created from it. Here's an example. I'm curious if anyone thinks this is not the intended use of the JSON package.<div><br></div><div>Feature require: 'JSON'<br></div><div><br></div><div>I have a class named <font face="monospace">VDog</font> that contains the instance variables <font face="monospace">id</font>, <font face="monospace">name</font>, and <font face="monospace">breed</font>.</div><div><br></div><div>Here is my instance method to generate a JSON string:</div><div><br></div><div><font face="monospace">jsonWriteOn: aWriteStream<br>    {<br>        #id->id.<br>        #name->name.<br>        #breed->breed<br>    } asDictionary jsonWriteOn: aWriteStream</font><br></div><div><br></div><div>Here is my class method to create a <font face="monospace">VDog</font> object from a JSON string.</div><div>It uses my class method <font face="monospace">id:name:breed:</font> to create a new instance.</div><div><br></div><div><font face="monospace">fromJson: aString<br>    | jsonObject |<br>    jsonObject := Json readFrom: aString readStream.<br>    ^VDog</font></div><div><font face="monospace">        id: (jsonObject at: #id)</font></div><div><font face="monospace">        name: (jsonObject at: #name)</font></div><div><font face="monospace">        breed: (jsonObject at: #breed)</font><br></div><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">Would you do this any differently?</font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jun 16, 2024 at 9:35 PM Ezequiel Birman via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>There is <b>Json class >> renderInstanceVariables:of:on:</b>. It generates a Dictionary. It still relies on Json class >> render, but may be enough for what you are trying to do. <br></div><div><br></div><div>Example:</div><div><b>Json renderInstanceVariables: Smalltalk class instVarNames of: Smalltalk on: Transcript.</b></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 17 Jun 2024 at 01:27, Mariano Montone via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
El 16/6/24 a las 20:25, Mark Volkmann escribió:<br>
> The WebClient package can generate JSON from a Dictionary.<br>
> Does Cuis provide a method that generates a Dictionary from the <br>
> instance properties of an arbitrary Object?<br>
> I looked for a method in Object or Dictionary that does that <br>
> conversion and couldn't find one.<br>
<br>
I believe there's no such method. Try to implement it yourself. Look at <br>
#allInstVarNames and #instVarNamed: .<br>
<br>
If you fail, let me know and I will give it a try.<br>
<br>
<br>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>