Then work out something that either works or gets you at least close. If you are just close post the work done to date and any relevant points of confusion.
I'll then likely be willing and able to fill in the missing gap(s) and provide a relevant explanation.
You should formulate your query so that it doesn't require CREATE TABLE. WITH vals (v) AS (VALUES (''::json)) SELECT vals.v FROM vals; makes experimenting very easy.
Also, indicate which version of PostgreSQL you are working with.