alnickels 0 Posted February 25, 2021 I have a JSON object that has two arrays. How can I retrieve the name of the array before I loop through all of the roes / elements? I am not sure if this is called an array name or a key. Share this post Link to post
Der schöne Günther 316 Posted February 25, 2021 (edited) An array is just an element, like any other. A Json Object is made up of pairs. Every pair has a name and a value. A value can be an array, text, float, ... Here is an example: program Project1; uses System.SysUtils, System.JSON; const input = '{'+ ' "someNumbers": [1,2,3],'+ ' "justOneNumber": 42,'+ ' "some Texts": ["Hello World", "My body is ready"]'+ '}'; var jsonObject: TJsonObject; pair: TJsonPair; begin jsonObject := TJsonObject.ParseJSONValue(input) as TJsonObject; for pair in jsonObject do if(pair.JsonValue is TJsonArray) then WriteLn('We found an array called "', pair.JsonString.Value(), '"'); ReadLn; end. It will output the following: We found an array called "someNumbers" We found an array called "some Texts" Edited February 25, 2021 by Der schöne Günther Share this post Link to post