Live data from Hacker News

Show HN: This website is valid JSON

webdatarender.com

171–180 of 240 posts

Re: Show HN: This website is valid JSON

#171

Earlier quoted context omitted.

It's kind of the author's problem and not ours. If they want to figure out how to make a quirks-mode page work correctly, be my guest. It will just be unnecessarily painful.

Maybe browsers should artifically delay the rendering of pages in the quirks-mode to create incentive for website creators to use proper formats/techniques. I can imagine the author had their fun, I also had fun reading the article, but I don't think this is leading to an accessible internet.

> Maybe browsers should artifically delay the rendering of pages in the quirks-mode to create incentive for website creators to use proper formats/techniques.

Interesting idea, but Google has a dominant position in both the browser space and the search-engine space. They can punish such pages in the Google search rankings, and this avoids the obvious retort of Why are you deliberately making my browser worse?

Re: Show HN: This website is valid JSON

#172

Earlier quoted context omitted.

Later versions of XSLT added support for more high-level output formats - JSON etc.

One of the big problems with XSLT, is that XSLT only started to become useful after Version 2.0, and wasn’t supported by languages at that level. This was the main reason I stopped using it. 2.0 was (maybe still is?) supported by Saxon, a proprietary library, needing to be licensed. Built-in support was capped at 1.5. If I remember, in order to run XSLT 2.0, you had to license and install Saxon on your server (i beli…

Saxon has an open source version that supports XSLT 3.0.

XQuery 3.1 has multiple open source implementations: Saxon, BaseX, xidel, and xqerl.

Re: Show HN: This website is valid JSON

#173
post #40
post #22

Earlier quoted context omitted.

Definitely your tooling is better incarnation of the idea, XSLT is kind of an abomination

I love XSLT in theory. It had the daring to say that the most frequently programmed thing that we do is just translate data structures of one shape into data structures of a slightly different shape, and it said “That is what I shall focus on, doing just that.” And the way that it produced that, by “just start writing your output document and insert XSLT when you finally need to loop or query the input” seemed quite…

I'm quite fond of DataWeave for this, as an FP-inspired data transformation language with plenty of built-ins, including support for XML, JSON and beyond [0].

Apparently there's an online playground [1] and Beta support for LSP now [2]. I've only ever used it in a containerized-Java setting.

[0]: https://mjdresdner.medium.com/dataweave-2-x-playground-comin...

[1]: http://dwlang.fun/

[2]: https://github.com/mulesoft-labs/data-weave-language-server

Re: Show HN: This website is valid JSON

#174
post #25

You know, I once had a resume powered by JSON. It was rendered to a PDF (and HTML) but the syntax was backed by JSON. This was years back and I shudder to even recall the idea. I didn't create the project mind you, it was some NPM package back when I was a fresh 'un who didn't have thoughts on using a billion subdependencies Anyway, I was nearly broke and when I went to apply for the benefit, I was asked for my resum…

LibreOffice and MS Word both can open PDFs, although maybe this happened before they could.

Re: Show HN: This website is valid JSON

#175
post #117

Earlier quoted context omitted.

You may also be entertained by my http://github.com/shadowcat-mst/App-plx/ project which has a script that produces a documentation page that's both valid HTML and a valid perl bootstrap installer for 'curl | perl -' purposes. An example of the output is at http://trout.me.uk/perl/plx.html (that one's actually served over http, it's a demo, please don't blindly run it).

Thanks for sharing, this is very cool. I'm also working on a Perl-HTML project, and I may reuse some of this :)

The HTML is just plain pod2html output, I should probably steal the mojolicious.org or perldoc.perl.org POD rendering to make it looks actually decent.

Feel free to drop by #perl and/or #mojo on freenode if you're interested in chatting more :D

Re: Show HN: This website is valid JSON

#176

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.

This is such a depressing comment. It's the opposite of the hacker spirit. The web has made it easier than ever to discourage people from trying anything new.

New ideas seem like bad ideas, because otherwise people would be doing them. One could imagine your objection applying to React: "What a horrible idea. It's a nice hack, but under no circumstances should you actually build webpages like this. Webpages are built out of HTML and valid JavaScript, which this is not..."

Re: Show HN: This website is valid JSON

#177

Earlier quoted context omitted.

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).

Or server sends explicit charset in HTTP header (`Content-Type: text/html; charset=UTF-8`), so meta element override is not needed at all. Naturally, there is no such header present in file:///.

Re: Show HN: This website is valid JSON

#178

Earlier quoted context omitted.

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.

This is such a depressing comment. It's the opposite of the hacker spirit. The web has made it easier than ever to discourage people from trying anything new. New ideas seem like bad ideas, because otherwise people would be doing them. One could imagine your objection applying to React: "What a horrible idea. It's a nice hack, but under no circumstances should you actually build webpages like this. Webpages are built…

I think the difference is that nothing in React is abusing fault tolerance in a browser to the extent that this is. This very specifically works only because browsers don't generally care that an HTML page is anything close to valid HTML. There's no guarantee at all that this will continue to be the case, and it's resonable to assume that some browser in the future might decide to do render things that are very clearly a JSON document as a JSON document instead - fundamentally breaking the core architecture of your system.

React is a different approach, but it plays by the rules and doesn't serve invalid HTML or Javascript.

Re: Show HN: This website is valid JSON

#179
Here's the page source:

```html

  {
      "#info": {
          "title": "WDR"
      },
      "subtitle": "Web Data Render",
      "title": "# WDR",
      "what": {
          "title" : "## What is WDR?",
          "description": [
              "This website is a valid **[JSON](//www.json.org/)**!",
              "Check the source code. Instead of the habitual HTML and CSS, you will see just a plain JSON with the website's information.",
              "WDR is a format to separate the website's **information** and **design**.",
              "The website is readily available to be consumed outside the browser via JSON, but also still presentable to users accessing through the web browser."
          ]
      },
      "subscribe": "I'm creating a **blog platform** using this concept. Follow me on [Twitter](//twitter.com/gpiresnt) to be notified when is ready! ",
      "how": {
          "title": "## How it works",
          "description": [
              "It works by embedding a small initiator at the end of the JSON file.",
              "For example, this is a valid JSON and web page:",
              "```{\n  \"title\": \"Example Page\",\n  \"description\": \"This is an example.\",\n  \"#render\": \"<html hidden><script src=/render.js></script></html>\"\n}```",
              "The script `render.js` receives the JSON as input and is responsible to render the page."
          ]
      },
      "usage": {
          "title": "## Usage",
          "description": [
              "First create an HTML file with the JSON information:",
              "```{\n  \"title\": \"Example Page\",\n  \"description\": \"This is an example.\"\n}```",
              "Include the initiator at the bottom:",
              "```{\n  \"title\": \"Example Page\",\n  \"description\": \"This is an example.\",\n  \"#render\": \"<html hidden><meta charset=utf-8><script src=/render.js></script></html>\"\n}```",
              "The next section explains how to create the `render.js`."
          ]
      },
      "only-data": {
          "title": "** Pure information **",
          "description": [
              "The JSON must contain only pure information without any concern about design or markup. All the design and markup required to render the page must be inside the rendering script."
          ]
      },
      "create-render": {
          "title": "## Creating a render",
          "description": [
              "Create a new javascript project and install the package `wdr-loader`:",
              "```npm install wdr-loader```",
              "Call the `loader` function to retrieve the JSON:",
              "```import loader from 'wdr-loader';\nloader(data => render(data));```",

              "Create a `render` function to handle the data and render the HTML. Below is an example using simple `innerHTML`:",

              "```function render(data) {\n    document.head.innerHTML = `\n      <meta charset=\"utf-8\">\n      <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n      <title>${data.title}</title>`;\n\n    document.body.innerHTML = `\n      <section>\n        <h1>${data.title}</h1>\n        <p>${data.description}<p>\n      </section>`;\n}```",

              "The `wdr-loader` code is available on [GitHub](//github.com/webdatarender/wdr-loader) with an example."
          ]
      },
      "basic-render": {
          "title": "## Basic render",
          "description": [
              "If you don't want to create a render right now, it is available a basic render (used on this very website) to immediate use:"
          ],
          "download": "[render-basic-1.0.3.js](//webdatarender.com/dist/render-basic-1.0.3.js)",
          "instructions": [
              "Just download the script and include it on the initiator directly:",
              "```{\n  \"title\": \"# Example Page\",\n  \"description\": \"This is an example.\",\n  \"#render\": \"<html hidden><meta charset=utf-8><script src=/render-basic-1.0.3.js></script></html>\"\n}```",
              "The code is available on [GitHub](//github.com/webdatarender/wdr-render-basic)."
          ]
      },
      "remarks": {
          "title": "## Remarks",
          "description": [
              "• The page is rendered in [quirks mode](//developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode) and can present some layout differences on different browsers.",
              "• Although javascript is necessary to render the page, most search engines, like [Google](https://developers.google.com/speed/pagespeed/insights/?url=webdatarender.com) or [Bing](https://www.bing.com/webmaster/tools/mobile-friendliness), will be able to read the page correctly.",
              "• If you want to display the JSON for users that have javascript disabled, you can include `noscript` at the initiator: ```<noscript><style>html{display:block !important; white-space:pre}</style></noscript>```"
          ]
      },
      "support": {
          "title": "## Need Help? ",
          "description": "If you need help, have any feedback or just want to say hi, send me an [email](mailto:gpiresnt@gmail.com)."
      },
      "about": {
          "creator": "Created by [@gpiresnt](//twitter.com/gpiresnt)",
          "logo": "![logo](/img/logo.png)"
      },
      "#render": {
          "_": "html{display:block !important; white-space:pre}",
          "css": "css/main.css"
      }
  }
```

Re: Show HN: This website is valid JSON

#180
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…

Here is the trick in a datauri nutshell:

     data:text/html,{"data":"Hello.","whatever":"onload=function(){document.body.innerHTML=''+JSON.parse(document.body.innerHTML).data+''}"}
Post reply on HN