Having Issues with Json data being undefined when trying to access it

Having an issue ive been trying to solve for a while,i want my client side to send a json object over to my websocket server using fastapi for use and the server to return an different or modified json object back.This part seemed to be working whenever logging the entire returned json object would display an object in the console. The issue comes when attempting to access specific data in the object,the console will log undefined instead of the expected value. I thought the issue was with my formatting but after checking several times my json is valid i still get this issue from even just echoing the json object back to the client.

client code

const ws = new WebSocket("ws://localhost:8000/ws");

ws.onmessage = (event) => {
  data = JSON.parse(event.data) // {"a":"a","b":"b"}
  console.log(data.a) // logs undefined