Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="container">
  <table></table>
</div>
              
            
!

CSS

              
                table {
  border-collapse: collapse;
}

tr {
  padding: 0;
  margin: 0;
}

td, th {
  border: 1px solid #000;
  padding: 2px 5px;
}

th {
  font-size: 13px;
  font-family: tahoma;
  text-align: left;
}

tr td {
  font-family: monospace;
  font-size: 13px;
}
              
            
!

JS

              
                // función para obtener las columnas en un objeto
function getRows(json, index) {
  var _index = index | 0;
  var row = [];

  // recorro el json por key
  for (key in json) {
    // agrego los textos correspondientes
    row.push({
      param: key,
      type: typeof json[key],
      example: typeof json[key] !== "object" ? json[key] : "",
      // esto es para saber la posición de los td
      _index: _index
    });

    // si es un objeto entonces lo recorro
    if (typeof json[key] === "object") {
      row = row.concat(getRows(json[key], _index + 1));
    }
  }
  return row;
}

var json = {
  HeaderJson: {
    Sistema: { codigo: "00001", nombre: "APP", lang: "es" },
    Traza: {
      timestamp: "2017-12-14T16:11:01.282Z",
      trazaID: "ASDA2232134124ASDS",
      Servicio: { nombre: "Orden", operacion: "Obtener" }
    }
  },
  BodyJson: { Orden: { ordenID: "1232132134" } }
};
var table = document.querySelector("table");
var rows = getRows(json);

// armo los tr y td para la tabla

// armo el header de la tabla
var tr = document.createElement("tr");
// obtengo el número máximo de _index
var tdLength = Math.max.apply(
  Math,
  rows.map(function(object) {
    return object._index;
  })
);
for (var i = 0; i <= tdLength; i++) {
  var th = document.createElement("th");
  var text = document.createTextNode(rows[i]._index === 0 ? "Parametro" : "");
  th.appendChild(text);
  tr.appendChild(th);
}
var thTipo = document.createElement("th");
thTipo.appendChild(document.createTextNode("Tipo"));
tr.appendChild(thTipo);

var thExample = document.createElement("th");
thExample.appendChild(document.createTextNode("Ejemplo"));
tr.appendChild(thExample);
table.appendChild(tr);

// recorro todos las columnas del objeto
for (var i = 0; i < rows.length; i++) {
  var tr = document.createElement("tr");

  for (var j = 0; j <= tdLength; j++) {
    var td = document.createElement("td");
    var text = document.createTextNode(
      rows[i]._index === j ? rows[i].param : ""
    );
    td.appendChild(text);
    tr.appendChild(td);
  }

  var tdTipo = document.createElement("td");
  tdTipo.appendChild(document.createTextNode(rows[i].type));
  tr.appendChild(tdTipo);

  var tdExample = document.createElement("td");
  tdExample.appendChild(document.createTextNode(rows[i].example));
  tr.appendChild(tdExample);

  table.appendChild(tr);
}

              
            
!
999px

Console