Setting keys from firebase into a dictionary

I have data in firebase for vehicle information that I am trying to pull into MIT App Inventor. When I click a button for year, make, or model I want there to be a list picker where select either the year, make, or model of your vehicle. Currently I am using web connectivity and using the REST api to get the json file from firebase. When I dont try putting it in a dictionary for trying to filter by the year, make, or model tag I can populate a label with the data from the json. When I try and put that information in a dictionary for just the tag year for example the label updates with "not found" which is the error check from the list.

Im pretty new to all of this, and Im sure there are some newbie mistakes being made. If anyone has some pointers it would be greatly appreciated.

Here is my block code

Here is the json data as it exported from firebase
{
"VehicleData": {
"-NN9Njdh2AuGizCnw4yu": {
""Body"": "Coupe",
""Engine"": "3.6L 3606CC H6 GAS SOHC Naturally Aspirated",
""Engine-Liter-Display"": "3.6L",
""Submodel"": "Carrera",
""Trim"": "Carrera Coupe 2-Door",
""Vehicle-Display-Name"": "Porsche 911 1997 Carrera",
""make"": "Porsche",
""model"": "911",
""year"": "1997",
""ymm_id"": "73920444"
},
"-NN9Njdh3JCxl-q25w6Y": {
""Body"": "Convertible",
""Engine"": "3.2L 3179CC H6 GAS DOHC Naturally Aspirated",
""Engine-Liter-Display"": "3.2L",
""Submodel"": "Roadster S",
""Trim"": "Roadster S Convertible 2-Door",
""Vehicle-Display-Name"": "Porsche Boxster 2003 Roadster S",
""make"": "Porsche",
""model"": "Boxster",
""year"": "2003",
""ymm_id"": "73920554"
},

Here is screen shot when I have it display the full json file being stored in the global VehicleYear variable.

Here is the screen shot when I am using the block code listed above trying to filter out just the year

You are using the list based JSON parse block.

There's a dictionary based parse block that will return a dictionary.

Look at the web block pallet.

You will need the dictionary block that walks the entire tree to get around those VIN keys.

You know you are receiving multiple cars, right?

Looking at your JSON fullscreen, I see something weird.

Your tags have quadruple quotes on them.

Here are some sample JSON filters and transformers you can study.

https://groups.google.com/d/msg/mitappinventortest/Kb_rpiKm8QU/mD7ARfw_CgAJ

Also, there are new list blocks in nb191 that can map, filter, and reduce tables.
See
https://ai2.appinventor.mit.edu/reference/concepts/pholo.html
from

Any further custom help would require posting exported .aia source here.

I do know that I am receiving multiple cars. the end goal is when you select year, it pulls and filters out each year in my file for someone to select, and then under make, it will list only the car makes that are in that year, and then when that make is selected, it will only show the cars for that year, and make for the user to select.

thank you for the response, Im going to take a look at those. It might have been the csv to json converter that cause the quadruple quotes, and then that data is what I used to populate the table in firebase

This works better in a tabular data store.

Here is an old sample, badly in need of refurbishment.

This can be done using dictionaries and lists. You will, however, need to tidy up and sort out the presentation of your returned json for this to work. You will also want to format the resultant json of the selected vehicle. The blocks work because they keep track of the index of each vehicle, while the user is filtering by year and make. This is why you see a number (index) with the car make and model in listpicker3. You could not show this in the listpicker, but you would need to retain it in the underlying list.

Example JSON Data
{ "VehicleData": 
	{ "-NN9Njdh2AuGizCnw4yu": 
		{   
			"Body": "Coupe", 
			"Engine": "3.6L 3606CC H6 GAS SOHC Naturally Aspirated", 
			"Engine-Liter-Display": "3.6L", 
			"Submodel": "Carrera", 
			"Trim": "Carrera Coupe 2-Door", 
			"Vehicle-Display-Name": "Porsche 911 1997 Carrera", 
			"make": "Porsche", 
			"model": "911", 
			"year": "1997", 
			"ymm_id": "73920444" 
		}, 
	  "-NN9Njdh3JCxl-q25w6Y": 
	  { 
		  "Body": "Convertible", 
		  "Engine": "3.2L 3179CC H6 GAS DOHC Naturally Aspirated", 
		  "Engine-Liter-Display": "3.2L", 
		  "Submodel": "Roadster S", 
		  "Trim": "Roadster S Convertible 2-Door", 
		  "Vehicle-Display-Name": "Porsche Boxster 2003 Roadster S", 
		  "make": "MG", 
		  "model": "Midget", 
		  "year": "1962", 
		  "ymm_id": "73920554" 
	   },
	 "-NT9Njdh3JCxl-q25w6Y": 
	  { 
		  "Body": "Convertible", 
		  "Engine": "3.2L 3179CC H6 GAS DOHC Naturally Aspirated", 
		  "Engine-Liter-Display": "3.2L", 
		  "Submodel": "Roadster S", 
		  "Trim": "Roadster S Convertible 2-Door", 
		  "Vehicle-Display-Name": "Porsche Boxster 2003 Roadster S", 
		  "make": "Ferrari", 
		  "model": "Dino", 
		  "year": "1997", 
		  "ymm_id": "73920554" 
	   },
	"-NZ9Njdh3JCxl-q25w6Y": 
	  { 
		  "Body": "Convertible", 
		  "Engine": "3.2L 3179CC H6 GAS DOHC Naturally Aspirated", 
		  "Engine-Liter-Display": "3.2L", 
		  "Submodel": "Roadster S", 
		  "Trim": "Roadster S Convertible 2-Door", 
		  "Vehicle-Display-Name": "Porsche Boxster 2003 Roadster S", 
		  "make": "Porsche", 
		  "model": "Boxster", 
		  "year": "1997", 
		  "ymm_id": "73920554" 
	   }
    }
}

Blocks

Screen

AIA
vehicleDataFB.aia (7.1 KB)

Whether it would be any easier using a tabular format (e.g. google sheets / csv tables) remains to be seen.

[EDIT]

Put the data in a google sheet....not much difference really, given the requirements

SHEET,SCREEN, BLOCKS

thank you for the suggestion. I am working on cleaning up the json file that I have loaded into firebase. I am hoping to have that done shortly and then I am going to give your suggestion a try.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.