Sorry, I glossed over the “store” aspect. You want to programmatically store JSON and that’s not possible with a custom macro.
I believe this may fulfill your requirements. It’s a Trigger-based Template Sensor with custom events for creating/deleting an attribute and its value. In other words, it offers the ability to create “variables”.
WTH can't input helpers be read only in UI - #13 by TheFes
Because it relies on attributes, the value can be up to ~16Kb in length.