{"id":340599,"date":"2021-05-20T15:29:53","date_gmt":"2021-05-20T22:29:53","guid":{"rendered":"https:\/\/css-tricks.com\/?p=340599"},"modified":"2021-05-20T15:29:56","modified_gmt":"2021-05-20T22:29:56","slug":"json-in-css","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/json-in-css\/","title":{"rendered":"JSON in CSS"},"content":{"rendered":"\n

Jonathan Neal tweeted a heck of a little CSS trick<\/a> the other day, putting JSON inside CSS and plucking it out with JavaScript. Valid values for custom properties<\/a> are quite liberal! So this looks for a CSS rule (e.g. a whole block, like #x { y: z; }<\/code> where the cssText<\/code> starts with --<\/code> (which is not a valid selector, but who cares\u2009\u2014\u2009you could change it if you want to thisIsJson<\/code> or something) and then slices out a string that JSON.parse()<\/code> works on. <\/p>\n\n\n\n\n\n\n\n

I re-typed his example here:<\/p>\n\n\n\n