How can I get a dictionary before a table?

Hi there, I have a midi player I am working on, which plays notes through a json table. The issue is, is that I do not know how to get the dictionary of instrument before a table of notes. I’ve tried indexing a dictionary by index (e.g: instrument[1]) however I only get carries with errors saying index nil. In the json table below, I basically want it so that the notes played print out the instrument name of the dictionary before the table its in.

Midi Player:

local owner = game.Players.LocalPlayer

local http = game:GetService('HttpService')
local response = http:GetAsync("https://vxsqi.tk/song.lua")

local jsondecoded = http:JSONDecode(response)

local function notetopitch(note)
	return (440/32)*math.pow(2,((note-0)/12))/440
end

local sounds = {}

function PlayMIDI(b)
	task.spawn(function()
		for i,w in ipairs(b.tracks) do
			task.spawn(function()
				for j,v in ipairs(w.notes) do
					task.spawn(function()
						task.wait(v.time)
						
						local s = Instance.new("Sound",owner.Character.Head)
						local ReverbSoundEffect = Instance.new("ReverbSoundEffect",s)

						s.Volume = 10
						ReverbSoundEffect.Density = 0
						ReverbSoundEffect.WetLevel = 5
						ReverbSoundEffect.DryLevel = -5
						ReverbSoundEffect.DecayTime = 5
						
						s.SoundId = "rbxassetid://584691395"

						s.RollOffMaxDistance = 25
						s.PlaybackSpeed = notetopitch(v.midi)
						s.PlayOnRemove = true
						game:GetService("Debris"):AddItem(s,1)
					end)
				end
			end)
		end
	end)
end

PlayMIDI(jsondecoded)

Example of json table (note it gets converted anyway):

"tracks" :  [
    "instrument": {
         "family": "piano",
         "name": "Grand Piano"
     },
     "notes" : [
         {
             "midi" : 67
         }
      ],
     "instrument": {
         "family": "reed",
         "name": "Clarinet"
     },
     "notes" : [
         {
             "midi" : 50
         }
      ]

This JSON is invalid and I’m surprised it parses (if it does).

The [] means “this is an array”, but you’re trying to still use keys like it’s an {} object.

Can you provide some valid json to illustrate your point?

1 Like

Surprisingly it does, however that’s just a example I made to show what I meant. The actual Midi converted JSON table is here is in my webserver: https://vxsqi.tk/song.lua (also seen in my Midi player script)

If you want, you can try my Midi player as a local script and you’ll see what I mean on how it only plays one instrument.