0

I am having a problem when using json2html https://github.com/eisenbraun/columns library . Is it possible to use this js library with Json object as below.

var jsonobj = [{
  "id": "31",
  "Mesial": {
    "disorder": "",
    "other": ""
  },
  "Facial": {
    "disorder": "DC-HP",
    "other": ""
  },
  "Distal": {
    "disorder": "",
    "other": ""
  },
  "Lingual": {
    "disorder": "",
    "other": ""
  },
  "Occlusal": {
    "disorder": "",
    "other": ""
  }
}, {
  "id": "37",
  "Mesial": {
    "disorder": "",
    "other": ""
  },
  "Facial": {
    "disorder": "RE-AR",
    "other": ""
  },
  "Distal": {
    "disorder": "",
    "other": ""
  },
  "Lingual": {
    "disorder": "",
    "other": ""
  },
  "Occlusal": {
    "disorder": "",
    "other": ""
  }
}]  

I have used online tool Convert JSON to HTML Table, but unfortunately it's library is not available.

expected table output is

snap enter image description here

4
  • 1
    You will need to flatten that array to match what you want shown in each column. It's not clear what expected table should look like. You can use Array#map() to map it to the needed structure Commented Nov 8, 2018 at 10:43
  • 1
    Please update the code you tried. Please check this for documentation michaeleisenbraun.com/columns Commented Nov 8, 2018 at 10:43
  • 1
    If you read the documentation you can see that the array needs to contain objects which define the columns, not further properties and subobjects: michaeleisenbraun.com/columns Commented Nov 8, 2018 at 10:43
  • Will try to implement a method to flatten the json object. so it may work Commented Nov 8, 2018 at 13:39

1 Answer 1

2

No, your data format is incorrect.

Your format need to respect their data format of :

[{"col1":"row1", "col2":"row1", "col3":"row1"}, {"col1":"row2", "col2":"row2", "col3":"row2"}]

Having for each object a colX:rowY format.

So you can't have an object as a row entry.

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

2 Comments

any suggestion to convert above json to flatten json?
@ArjunaBandara it depends on which values you want to keep in your actual json before converting it, but that's another question :)

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.