Live data from Hacker News

Show HN: This website is valid JSON

webdatarender.com

121–130 of 240 posts

Re: Show HN: This website is valid JSON

#121
post #44

For those like me who needed a little help... I do not fully understand the browser rendering process (someone who does please chime in), but what I gather about how this is works is: - the content-type of the page is "text/html", so the browser is trying to render html - there is no special meaning of the #render key to the browser (again the browser doesn't know this is json) - browsers are very fault tolerant so t…

You are correct. It's a silly hack. Just because it happens to work doesn't make it a good idea. Turn off JavaScript and you just get JSON text.

The page says:

> I'm creating a blog platform using this concept.

Yeah, please don’t; this is an abomination that’s fun for demonstrating and teaching how these things work, but should absolutely never be used in reality.

You could use this as your data model foundation upon which to build a generator, but you should never under any circumstances actually serve this stuff.

Re: Show HN: This website is valid JSON

#122
post #99
post #10

This is a really cool hack. > The JSON must contain only pure information without any concern about design or markup. Wellll.. I mean the json has markdown syntax in it. That's a lot nicer than html tags for markup, but it's still markup. In case anyone reading hasn't seen it before, browsers have a thing called XSLT built into them that does something similar for XML documents. You serve up your data as XML, add a t…

> Apparently web standards folks in the early 2000s thought the future was XML all the way down. It should have been, but just like the masses rejected LISP for its parens, the masses rejected XML for the closing tag. We could have avoided PHP and the zoo of MVC frameworks.

If only XML wasn't so damn complicated, it might have had a chance. People love to point at close tags, but there's a long list of more serious problems.

External entities, namespaces within namespaces, CDATA, namespaces that confusingly look exactly like URLs, but aren't, parser vulnerabilities.

Re: Show HN: This website is valid JSON

#123
post #44

For those like me who needed a little help... I do not fully understand the browser rendering process (someone who does please chime in), but what I gather about how this is works is: - the content-type of the page is "text/html", so the browser is trying to render html - there is no special meaning of the #render key to the browser (again the browser doesn't know this is json) - browsers are very fault tolerant so t…

You are correct. It's a silly hack. Just because it happens to work doesn't make it a good idea. Turn off JavaScript and you just get JSON text.

Very good hack. Can we use Google structured data json+ld without validation issue? For example, https://developers.google.com/search/docs/data-types/course#... ?

Re: Show HN: This website is valid JSON

#124

The json.org description of an "object" is: > An object is an unordered set of name/value pairs. But this site seems to be assuming that the key/value pairs are parsed in their original ordering for everything to display properly. Is it safe to assume JavaScript will always parse the keys in order?

ECMAScript 2015 defines object iteration order as: number keys in ascending order, then other string keys in insertion order, then symbol keys in insertion order. See https://stackoverflow.com/questions/5525795/does-javascript-....

And then JSON.parse is defined as doing the obvious and only sane thing, setting each property as it goes.

Consequently, so long as your keys are not numeric, yes, JavaScript guarantees that it will all be in order.

But that’s for JavaScript. It is incorrect to treat JSON objects as ordered, because various libraries in various languages will discard the order for various reasons (e.g. efficiency, DoS resistance), since it is defined as being not significant. If you care about the order of things, use an array instead.

Re: Show HN: This website is valid JSON

#125
post #120

Prior art (rather similar, but instead of being json, it's a JPEG): https://news.ycombinator.com/item?id=12262470 tldr: the html is stuffed in the exif data!

A similar approach is (over)used for codegolfing, namely the PNG bootstrapping method [1] [2] [3]: your code is compressed into a PNG image and the bootstrap in HTML gets appended to the PNG file to decompress and eval the code. The exact method requires some experiments, as browsers change their rules to determine which is a valid image and which is a valid HTML.

[1] https://gist.github.com/gasman/2560551

[2] https://github.com/codegolf/zpng

[3] https://xem.github.io/terser-online/ (If you pick the packing method "Zopfli (DEFLATE)", open the zopfli options and change the format to "zpng", you can write directly to the "Minified (Terser)" input to download the optimized PNG. Yes I wrote that part of code and that required way too much algorithm: https://github.com/xem/terser-online/blob/5cc33125/compress....)

Re: Show HN: This website is valid JSON

#126

Earlier quoted context omitted.

You are correct. It's a silly hack. Just because it happens to work doesn't make it a good idea. Turn off JavaScript and you just get JSON text.

The page says: > I'm creating a blog platform using this concept. Yeah, please don’t; this is an abomination that’s fun for demonstrating and teaching how these things work, but should absolutely never be used in reality. You could use this as your data model foundation upon which to build a generator , but you should never under any circumstances actually serve this stuff.

Moreover this is not even a "plain JSON". While I don't think the OP doesn't make this exact claim, an arbitrary JSON with the `#render` bootstrap won't necessarily work because the JSON can contain valid HTML tags... Interesting as it stands, utterly useless in practice.

Re: Show HN: This website is valid JSON

#127
post #80

Earlier quoted context omitted.

hmm, I didn't find this error locally either. I will try using file://. Thanks for the report. Also, if you are interested, the project is on GitHub: https://github.com/webdatarender

The reason it works locally is because charset detection works different when loading from a local file than when loading from a webserver. In particular browsers tend to be a lot more enthusiastic about treating local files as unicode than they are for responses from web servers. The reason the meta charset doesn't pick up is you're missing quotes around `utf-8` (also it may be past the 1024 byte mark, hard to say w…

The reason browsers' charset autodetection works differently locally is likely because HTTP standard specifies Latin1 (ISO-8859-1) as the default encoding (at least in 1.1).

Re: Show HN: This website is valid JSON

#128
At my previous job I worked at a whole UI framework (server side) based on XSLT transformations. We built kind of abstraction layer on top of ExtJS,HighCharts and some 3D rendering lib at that time. It was hell to debug anything in there because the output was HTML sprinkled with JavaScript and it was not always easy to identify what part of XML and XSLT was responsible for given part of output. It was quite successfully used in one internal ERP mashup app that sucked data out of some SAP system. Learning XSLT actually helped me understand C++ templates (big aha moment). So we had this XSLT monster crunching on XML files but what we really needed was JSX which probably wasn't a thing until few years into the project.

Re: Show HN: This website is valid JSON

#129
Yes yes, sperate content and markup/style. But you can already do this with HTML?

The only advantage I see is that you can actually support markdown like you do in your page, since it's less verbose than HTML-tags and doesn't make the text unreadable if you read it as plain text.

But with HTML5 you can introduce arbitrary tag names to pretty much get the same with an XML-like structure instead of json. Just use and supply CSS for it. If you want to consume it with something else, swap out the JSON parser for an XML one, navigate to the body tag and from there on it's the same thing.

I mean it's a cool trick you came up with, but it doesn't seem worth the effort, and relying on quirks mode seems brittle.

Post reply on HN