Nested json file to datatables.

Nested json file to datatables.

oppsigoppsig Posts: 2Questions: 1Answers: 0
edited April 2019 in Free community support

Hello, so I'm not really that accustomed to javascript.
But i have a nested json file with syntax like this.
So each key is a string containing a number.

How do i loop over this and add to datatables.net

{
  "123456789": {
    "Poststed": "Blahblah",
    "Boguscol": null,
    "Worth": null,
    "date_observed": "2019-04-04T23:22:48",
    "Price": 5649650,
    "Monthly": null,
    },
    "167872782": {
    "Poststed": "Gjøvik",
    "Boguscol": null,
    "Worth": null,
    "date_observed": "2019-04-04T23:23:25",
    "Price": 4613722,
    "Monthly": null,
    }
}

This is what i got so far.

<script>
    var $  = require( 'jquery' );
    var dt = require( 'datatables.net' )();
    var buttons = require( 'datatables.net' )();
    $(document).ready( function () {
        $('#example').DataTable({
            "ajax": "latest.json"
        });
    } );
</script>
<table id="example" class="display table table-striped table-bordered" style="width:100%">
    <thead>
        <tr>
            <th>key</th> # How do i create a column here for the initial keys, like "123456789"
            <th>Price</th>
            <th>Poststed</th>
        </tr>
    </thead>
</table>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735
    Answer ✓

    This thread is asking the same question. See if it helps.

    Kevin

  • oppsigoppsig Posts: 2Questions: 1Answers: 0

    Ok, thanks, seams like he has the exact same structure as me, hopefully i can figure it out.

This discussion has been closed.