Json Count lazarus / 21-General ---------------------------------------------------------------------- michoux · 2021-01-09 22:18 Hello, During my application I am creating a simple json record ... something like this { "BIB1":12:11:03.73200_00000, "BIB1":12:11:03.73200_00000, "BIB1":12:11:03.73200_00000, "BIB2":12:11:03.73200_00000, "BIB14":12:12:03.73200_00000, "BIB18":12:12:03.73200_00000, "BIB14":12:11:03.73200_00000 } At some point I would like count number of let say BIB1 records. I tryed with findpath FindPath('BIB1').count But this allways give 0 ...  Thanks ---------------------------------------------------------------------- lainz · 2021-01-09 23:37 QuoteCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {"BIB1":12: 11:03.73200_00000,"BIB1":12:11:03.73200_00000,"BIB1":12:11:03.73200_00 000,"BIB2":12:11:03.73200_00000,"BIB14":12:12:03.73200_00000,"BIB18":1 2:12:03.73200_00000,"BIB14":12:11:03.73200_00000} Hi, I don't want to be rude, but in JSON the sample code you posted is not valid. An object can't contain two same keys with the same name. BIB1 must be unique to that single object. If you mean you created an array of objects, and each object can contain different keys, that is valid. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [{"BIB1":...},{"BIB1":...},{"BIB2":...}] Basically .count returns the length of the array. Depending on the JSON object you're using, .count as well only returns the ammount of keys you have (in Pascal). In JavaScript you can use .filter to return only the objects that contains "BIB1" as key, and count that resulting array. In Pascal you need to iterate the entire array, look if there is the name "BIB1" with the property "key" or "names" depending on the JSON library you're using. And just count that with a counter. ---------------------------------------------------------------------- avk · 2021-01-10 06:35 This JSON sample is syntactically invalid, but RFC 8259 does not prohibit objects with non-unique keys. If this JSON is replaced with, say, this one: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   {    "BIB1":  "12:11:03.73200_00000",    "BIB1":  "12:11:03.73200_00000",  "BIB1":  "12:11:03.73200_00000",    "BIB2":  "12:11:03.73200_00000",    "BIB14": "12:12:03.73200_00000",    "BIB18": "12:12:03.73200_00000",    "BIB14": "12:11:03.73200_00000"  } then lgJson.TJsonNode will respond to the CountOfName('BIB1') request with 3. ---------------------------------------------------------------------- lainz · 2021-01-10 15:08 I didn't know. Since in JavaScript it takes only the last value, so is basically a bad desing for web development I did this in the Chrome console: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var a = '{"a":"b","a":"d"}'undefinedJSON.parse(a){a: "d"} So the last name is only taken into account. Anyways if it works in Pascal you're good to go. ---------------------------------------------------------------------- eny · 2021-01-10 22:02 Code: [Select]{   "BIB1": [ "12:11:03.73200_00000",             "12:11:03.73200_00000",             "12:11:03.73200_00000" ],   "BIB2": [ "12:11:03.73200_00000" ],   "BIB14": [ "12:12:03.73200_00000",              "12:11:03.73200_00000" ],   "BIB18": [ "12:12:03.73200_00000 " ] } Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   ...  ...  NbOfBIB1 := js.Find('BIB1').Count;