PizzaProgram 9 Posted November 11, 2022 (edited) My code looks currently like this, but it is causing AV error. 😞 function JSONt_array_Creator(z1: string) : SOString; var o, n: ISuperObject; begin Result := ''; o := SO(); insert_other_JSON_data( o ); n := SO(); n.S['id'] := z1 ; o.O['identifiers'].AsArray.Add( n ); // << ERROR Result := o.AsJSon(); n := nil; o := nil; end; The result should look like this { "base": "something", "identifiers": [ {id: 2} ] }  There are many many SO examples out there, but all about "how to parse / read / digest ..." not a single one about "how to CREATE SO sub-tree or array ... ".  Edited November 11, 2022 by PizzaProgram Share this post Link to post
FPiette 383 Posted November 11, 2022 On which line EXACTLY does your code cause an AV? Â Share this post Link to post
Angus Robertson 574 Posted November 11, 2022 ISuperObject documentation and examples are very poor, but it's a reliable and fast library...  There is an example in the OverbyteIcsSslX509Certs.pas unit, search for SA([]) which creates an empty array, then you can add elements with a blank name to create a simple array.  Angus    1 Share this post Link to post
PizzaProgram 9 Posted November 11, 2022 This method works: 🙂  n := SO(); n.S['id'] := z1 ; o.O['identifiers'] := SA([ n ]);  Share this post Link to post
stijnsanders 35 Posted November 11, 2022 In case anyone wants to try out an alternative, with the JSON library I wrote based on variants, it would look like this: Â o := JSON(['base','something','identifiers',VarArrayOf([JSON(['id',z2])])]); Â Share this post Link to post
FPiette 383 Posted November 11, 2022 1 hour ago, PizzaProgram said: This method works: 🙂 Is your problem solved? If not, on which line EXACTLY does your code cause an AV? Run your program under the debugger using the debug release. Share this post Link to post
PizzaProgram 9 Posted November 11, 2022 5 minutes ago, FPiette said: Is your problem solved? YES, thank You! 🙂  OFF: I think the problem was, that first we need to create an Array on that level, and we can .Add() elements only after that.  Maybe you can improve the code later to add "auto-array-creation" in those cases, but it's not necessary. Some better examples can do it also.  I would do it myself, but I have a nearing deadline and already working 14-16 hours pro day. Sorry. 1 Share this post Link to post