-2

I have JSON that looks like this:

data: [{
  test: {
    innertest: "2345",
    outertest: "abcd"
  },
  trans: {
    sig: "sou",
    trip: [{
      one: "2"
    }, {
      two: "3"
    }],
    otherac: "iii"
  },{
    test: {
      innertest: "uuu",
      outertest: "rrr"
    },
    trans: {
      sig: "e",
      trip: [{
        one: "9"
      },{
        two: "8"
      }],
      otherac: "eee"
    }
  }]

I need to create an interactive and expandable preview for this JSON in HTML. Can anyone suggest how to do this?

Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
mammam
  • 129
  • 4
  • 17
  • in angularjs or plain javascript – zabusa Jan 22 '18 at 10:23
  • 2
    That's not [JSON](https://json.org). _"JSON is a textual, language-indepedent data-exchange format, much like XML, CSV or YAML."_ - [What is the difference between JSON and Object Literal Notation?](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation) – Andreas Jan 22 '18 at 10:24
  • i am using angular 2. any things is fine for me, – mammam Jan 22 '18 at 10:24
  • 1
    You mean this `$scope.your_json = ....;` -> `
    {{your_json | json}}
    `?
    – Aleksey Solovey Jan 22 '18 at 10:25
  • i will get like this data from response, now i need to show using html ( how we see preview in chrome ) – mammam Jan 22 '18 at 10:26
  • ok, I ll try to creating boxes, preview means i want to say, if we expend we can check inside the test object, like that, how in google chrome (developer mode) network have preview box, like that – mammam Jan 22 '18 at 10:46
  • 1
    @mammam then forget about my suggestion it's not what you want. You should consider [angular-json-tree](https://github.com/awendland/angular-json-tree) look at [this example](https://codepen.io/timbrown81/pen/QEyZrL) – Aleksey Solovey Jan 22 '18 at 14:00

3 Answers3

0

You can use the filter "json" provided by angular to do this;

{{data | json}}
Tom Johnson
  • 679
  • 5
  • 15
0

You can use the filer "json" in HTML file as :

<pre ng-bind="data|json"></pre>
Chiru Adi
  • 647
  • 4
  • 21
0

I'm not sure if you're using AngularJS or other version, but I think you're looking for something like json-formatter, if it's AngularJS you're using.

Just add it to your app module has you would do with any other module and use the directive:

<json-formatter json="{my: 'json'}" open="1"></json-formatter>

If you're using Angular2 instead of AngularJS, maybe you can try angular2-prettyjson.

pgrodrigues
  • 2,083
  • 1
  • 24
  • 28