I'm trying to figure out how to make a function that takes an input then uses it to grab a specific JSON object.
My data is in rpcData
but I want the input from the obj
function parameter to expand on this.
For example obj = ".market_data.current_price.usd"
which would then be appended to JSON.stringify(rpcData)
making it JSON.stringify(rpcData.market_data.current_price.usd)
export const Blockchain = ({ path, obj }) => {
const { rpcData, isLoading, isError } = fetchRPC(path);
if (isLoading) return <Loading />;
if (isError) return <Error />;
return JSON.stringify(rpcData);
};
Using one of the answers from here I was able to get it to work up to one level deep with JSON.stringify(rpcData[obj])
when obj="height"
but still can't get it to work with deeper nested objects.