Giter VIP home page Giter VIP logo

ng-json-explorer's Introduction

ng-json-explorer

I AM NO LONGER MAINTAINING THIS PROJECT - please let me know if you would like to adopt it.

Simple json explorer angular directive that uses raw json data as source.

This module is based in the firefox jsonview extenrsion made by Ben Hollis: https://github.com/bhollis/jsonview/

Properties

The directive has the following properties:

  • data: json content to be displayed (needs to be and object or array);
  • json-data: alias for data
  • url: An string url to be fetched (HTTP GET) or an object to be used by $http service;
  • collapsed: a boolean value to collapse (or not) objects/arrays content when the data is loaded/parsed;
  • sort-by: a field to used as reference to order the json data (should be an array): sort-by="counter:asc" or sort-by="name:desc".

Styling

Check src/angular-json-explorer.css

Usage

Check the demo folder (demo/index.html) for examples.

Installation

bower install ng-json-explorer

Module dependency

angular
.module('app', ['ngJsonExplorer'])

Files to be used in production are located in the folder "ng-json-explorer/dist"

Including the required files (js and css)

<script src="angular-json-explorer.min.js"></script> 
<link rel="stylesheet" type="text/css" media="screen" href="angular-json-explorer.css" />

Sending the json data to your template

$scope.data = {
	"name": "Json Explorer",
	"qty": 10,
	"has_data": true,
	"arr": [
		10,
		"str",
		{
			"nested": "object"
		}
	],
	"obj": {
		"hello": "world"
	}
}

Usage

Check the demo folder (demo/index.html) for a simple example.

Using the directive to display the data (you can use either "json-data" or "data")

<json-explorer json-data="data"></json-explorer>
<json-explorer data="data"></json-explorer>

Using the directive to display the data from a URL

<json-explorer url="http://myurl.com"></json-explorer>

Using the collapsed attribute

<json-explorer json-data="data" collapsed="true"></json-explorer>
<json-explorer data="data" collapsed="true"></json-explorer>

Using the directive to display the data

<json-explorer json-data="data"></json-explorer>
<json-explorer data="data"></json-explorer>

Using the directive to display the data from a URL

<json-explorer url="http://myurl.com"></json-explorer>

Using the collapsed attribute

<json-explorer json-data="data" collapsed="true"></json-explorer>
<json-explorer data="data" collapsed="true"></json-explorer>

ng-json-explorer's People

Contributors

amitapl avatar andipexton avatar dependabot[bot] avatar epugh avatar jibwa avatar jmendiara avatar maeisabelle08 avatar odra avatar plaflamme avatar superboum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ng-json-explorer's Issues

Is it possible to dynamically change the collapsed flag ?

I 'd like to propose a button to collapse or expand the json view in my page.
I tried to use $watch (angular watcher) to do it by changing the value of the collapsed tag in HTML dynamically each time I click. But it doesn't work.

Do I do something wrong or may it's not possible.

HTML :

My click definition

<h2 class="panel-title pull-left">{{selectedConsumption.contractList.contract[0].usageConsoList.usageConso[0].usageKey}}</h2><span class="pull-right" ng-click="toggleCollapse()">+</span>

My Json Explorer item

<div class="panel-body"> <json-explorer json-data="{{selectedConsumption}}" collapsed="{{collapse}}"></json-explorer> </div>

Javascript :

sccController.controller('ConsumptionCtrl', ['$scope', 'ConsumptionService',
    function($scope, ConsumptionService) {

        $scope.collapsed = true;

        ConsumptionService.getAll(function(data) {

            $scope.consumptions = data;
            $scope.selectedConsumption = data;
        });

        $scope.details = function(consumption) {
            $scope.selectedConsumption = consumption;
        };

        $scope.toggleCollapse = function() {
            $scope.collapsed = !$scope.collapsed;
        };

        $scope.$watch('collapsed', function(newval, oldval) {
            $scope.collapse = newval;
        });
}]);

Thanks

Explorer does not display

Hi guys,

I have tried this in a few apps now and aside from the demo I cannot get it to work.

I always end up with something like the following when I look at the element.

""

where {...} is the json data

{ "id": "54cbbbc8bf3cba42aea6ffc4",
"index": 0,
"guid": "0127d734-75a3-4d76-8ad5-8af0478043dd",
"isActive": false,
"balance": "$3,775.10",
"picture": "http://placehold.it/32x32",
"age": 22,
"eyeColor": "brown",
"name": "Arnold Romero",
"gender": "male",
"company": "BUZZOPIA",
"email": "[email protected]",
"phone": "+1 (973) 531-2834",
"address": "999 Rapelye Street, Fowlerville, Illinois, 1664",
"about": "Eiusmod ex velit voluptate veniam culpa. Cupidatat aliqua consectetur reprehenderit cupidatat pariatur sunt velit ut ad non veniam id proident fugiat. Aute aliquip consequat ullamco incididunt cupidatat. Nostrud pariatur eu ex deserunt pariatur mollit reprehenderit sunt in qui. Velit proident deserunt quis commodo esse duis consectetur Lorem magna nostrud culpa.\r\n",
"registered": "2014-05-12T12:59:32 +03:00",
"latitude": 20.153763,
"longitude": 42.329199,
"tags": [
"ut",
"ad",
"consequat",
"eu",
"ea",
"do",
"aliqua"
],
"friends": [
{
"id": 0,
"name": "Terra Booker"
},
{
"id": 1,
"name": "Gilmore Saunders"
},
{
"id": 2,
"name": "Nash Riggs"
}
],
"greeting": "Hello, Arnold Romero! You have 9 unread messages.",
"favoriteFruit": "banana"
}

Default Collapse State?

Could you enhance this to have the ability to indicate if you want to have the initial state of the "collapser" to be collapsed?

<json-explorer json-data="{{json}}" collapsed="true"></json-explorer>

Just some added information, I did do the quick hack of just calling click during the processing of each collapser a found that it hangs the browser. Same case if i select all the collapsers after and call click. I know this was a hack for the purposes of my "demo" of what i wanted my page to look like on load. I thought id mention it so it wasn't suggested as a solution. Performance wise it will make sense to handle it in the directive. I thought it would be a nice little feature for you to add.

If i get some time i might throw together a pull request but i cant right now.

Unnecessary line of code?

In trying to figure out an error I'm getting I came across something out of place:

On line 201 in the current master is this line:

var ellipsis = target.parentNode.getElementsByClassName('ellipsis')[0];

This does nothing, the var ellipsis is not used anywhere that I can determine.

I thought maybe I could figure out my other issue by searching for that line of code since you mention it's based on another project and I found the same line of code in an online search but it's for a chrome json viewer plugin I think (not firefox related) so perhaps there was some experimentation going on? In any case there is a bug of some kind in this area (which I'll report separately as soon as I figure it out) and this bit of code is not doing anything.

Collapse fails

I just got the most recent release from bower and when clicking collapse there is some logic that fails. I'll submit a pull request

Should handle empty json as that is not an unusual condition

Hello, in my app data is brought down via api from a server so there is no immediate value in the binding to the json explorer and as a result a nasty parse error is displayed in the console.

To work around I simply set a fake bit of json before the view goes to get the json from the api which avoids the error.

However this is really a bug I think as that is not an unusual condition.

I suggest that the piece of code in line 188:

  var json = JSON.parse(val);

Be modified to handle the very likely event that val is undefined or empty and not attempt to parse empty json so that a JSON parse error is not displayed in console unnecessarily.

minified version don't display boolean attributes

The JSON boolean props was not showing up ini the explorer. I was using the dist/angular-json-explorer.min.js version, i changed for the dist/angular-json-explorer.js version and it works fine.

data or json-data

The documentation and previous versions used an attribute json-data. The example show this attribute.
But the last version available uses "data".

Is-it possible to authorize the two ?

Edit the JSON

Hi
This is really awesome.
I would like to know if there is an option to edit the json?

Regards
Deepthi

Update bower key in readme

The readme shows the installation via bower install ng-json. This should be bower install ng-json-explorer.

Uncaught TypeError: Cannot read property 'style' of undefined gd-ui-jsonexplorer.js:207

I am testing this with a fairly large chunk of JSON. It loads and displays correctly as far as I can tell but when I go to collapse some subsections I get that error message.

Note that this same exact json works correctly with the online json viewer here:
http://www.jsoneditoronline.org/ and it parses correctly in ng-json-explorer without error, this seems to be linked to the collapsible stuff.

I can provide the data to you but only out of band, not posted here, let me know please.

That whole area of code appears to need some love, there are unused statements in there (line 201) and it looks like some kind of problem causing this error but I can't pin it down.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.