1

I'm trying to display a more complex json output into html and I haven't been able to figure out how the transform should be constructed using node-json2html

My json looks like this:

[
  {
    "name": "flight.LOL123 ",
    "columns": [
      "time",
      "sequence_number",
      "vert_rate",
      "messages",
      "squawk",
      "altitude",
      "lat",
      "lon",
      "validposition",
      "track",
      "validtrack",
      "speed",
      "seen",
      "hex"
    ],
    "points": [
      [
        1434558860921,
        98792710001,
        -512,
        1018,
        "4543",
        3325,
        15.74181,
        71.60743,
        1,
        290,
        1,
        207,
        0,
        "4692d4"
      ],
      [
        1434558000838,
        98401040001,
        0,
        4,
        "0000",
        25550,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        "4692d4"
      ]
    ]
  }
]

I was able to get this:

var transform = {'tag':'li','html':'${name}, ${points}'};

but it will produce a first line containing the name and then the points are all on a single, long line.

Can anyone help me try to get the transformation right?

2 Answers 2

1

For what I see, you use quite different formatting compared from the example of the library you mention.

Once again the official example format:

 var data = [{'male':'Bob','female':'Jane'},{'male':'Rick','female':'Ann'}];

Your formatting is nested, not flat as it should be.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the answer Dejan! Unfortunately I cannot change the formatting, can I still somehow display it a bit more readable in HTML?
Why you don't pass the object to Jade and render it within the jade file?
Had no idea that Jade can do this for me, everywhere I've searched the node-json2html came back; thank you!
Even better- use jspath(NPM) to make any fancy filtering and then you pass to Jade much simplified data. This in case you can't make Jade work with your object.
1

Found another faster and pretty solution by using mustache.js

This code is for my original JSON:

            {{#.}}

            <div class="panel panel-info">
            <div class="panel-heading"><h2>Data for {{name}}</h2></div>
            <div class="panel-body"></div>

            <table  class="table table-striped">
            {{#columns}}
                <th>{{.}}</th>
            {{/columns}}

            {{#points}}
                <tr>
                  {{#.}}
                     <td>{{.}}</td>
                  {{/.}}
                </tr>
            {{/points}}

            {{/.}}
            </table>

            </div>

With only these I'm populating tables of >5k lines in a heart beat. Pretty cool stuff!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.