Get value from nested JSON in firebase

how do i get AMOUNT value for ID 872228 from below json stored in firebase

{
“PENDING”: [
{
“AMOUNT”: 150.6,
“ID”: 872228,
“NAME”: “Aman Abdul Khalek 1 - ABJ”
},
{
“AMOUNT”: 80,
“ID”: 817901,
“NAME”: “Mahi uddin 1 - ABJ”
},
{
“AMOUNT”: 154,
“ID”: 1745803,
“NAME”: “Dipesh Kalal Natwar Lal Kalal 1A - ABJ”
},

can someone help me with the blocks. Thanks in advance

first of all, your json is not valid.

  1. json doesn’t have left quotations marks and right quotation marks (your sample does). Json uses only the quotation mark for both opening and closing a string.
  2. json usually starts with a non-array item, not an array (like your sample does)
  3. every opening quote and brace should have a matching ending quote and brace - your sample doesn’t meet these conditions because you just decided to cut-n-paste a segment and missed the beginning and end of the whole json string.
  4. the json string is not “quoted” properly for viewing . Next time you want to share some json code or program code or parameter data, etc, in our thunkable forum, please highlight it and click the preformatted icon

anyway, i went ahead and corrected your json so it looks like this - i made the PENDING array part of the object called root;

{"root":{
"PENDING": [
{
"AMOUNT": 150.6,
"ID": 872228,
"NAME": "Aman Abdul Khalek 1 - ABJ"
},
{
"AMOUNT": 80,
"ID": 817901,
"NAME": "Mahi uddin 1 - ABJ"
},
{
"AMOUNT": 154,
"ID": 1745803,
"NAME": "Dipesh Kalal Natwar Lal Kalal 1A - ABJ"
}]}}

after you get a json string, paste it to this website https://jsonbeautify.com/ to see its structure (and also validate the format)

this is what your json really looks like:

{
  "root": {
    "PENDING": [
      {
        "AMOUNT": 150.6,
        "ID": 872228,
        "NAME": "Aman Abdul Khalek 1 - ABJ"
      },
      {
        "AMOUNT": 80,
        "ID": 817901,
        "NAME": "Mahi uddin 1 - ABJ"
      },
      {
        "AMOUNT": 154,
        "ID": 1745803,
        "NAME": "Dipesh Kalal Natwar Lal Kalal 1A - ABJ"
      }
    ]
  }
}

in order to get the AMOUNT that Dipesh owes, code the following:

the join block is actually forming the concatenated key/property
root.PENDING[3].AMOUNT

in order to find out how many items are in the PENDING array, you would code this:

good luck!

1 Like

Thanks manyone, i have seen your replies on multiple posts, thanks for trying to help everyone. my json is from firebase database and its working fine. PENDING is my cloud variable and ID is app variable.


these blocks works fine but anyway i will check your solution too.