-1

A part of my assignment requires me to make a converter that as the title suggests, reads -any- JSON file and converts it into an HTML file.

Having scoured the web, I've personally found naught except people converting hand made JSON files into HTML ones, but the problem with that is that they are preset and I need to be able to read any JSON file instead of a premade one.

  • How do you expect to convert a bicycle into a banana? JSON and HTML are fundamentally different things, it's not like converting a PNG to a JPG. Please clarify the input and expected output. – Thomas Sep 23 '20 at 09:45
  • What would converting to html entail? Pretty-printing it? Outputting an html that mimics the structure of the json (like `{"html": {"body" : "hello"}}`->`hello`)? – Federico klez Culloca Sep 23 '20 at 09:45
  • Hello, and welcome to Stack Overflow. Your question lacks information that is required for us to answer it. What we need to know is: will the JSON elements be directly translated to HTML, as if the JSON file _is_ the HTML file in disguise? Or are you merely supposed to _show the contents_ of the JSON file in an browser friendly manner? – MichaelK Sep 23 '20 at 09:46
  • I'm supposed to show the contents in a browser friendly manner. Sorry, it is my first time posting here so my question might be a bit unclear. – Raccoonmancer Sep 23 '20 at 10:06

1 Answers1

0

Easy:

<html>
  <body>
    <pre>
      $jsonContent
    </pre>
  </body>
</html>

If you can't make any assumptions on the structure of the json, there is not more you can do. If you know the structure of the json, you can try things like:

Or do all in one: XSLT equivalent for JSON

Conffusion
  • 4,335
  • 2
  • 16
  • 28