Gathering detailed insights and metrics for ngx-json-builder
Gathering detailed insights and metrics for ngx-json-builder
Gathering detailed insights and metrics for ngx-json-builder
Gathering detailed insights and metrics for ngx-json-builder
npm install ngx-json-builder
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
172 Commits
1 Branches
1 Contributors
Updated on 18 Jul 2023
TypeScript (83.39%)
JavaScript (9.11%)
HTML (7.1%)
SCSS (0.41%)
Cumulative downloads
Total Downloads
Last day
-81.8%
2
Compared to previous day
Last week
23.7%
47
Compared to previous week
Last month
-14.8%
161
Compared to previous month
Last year
260.6%
1,410
Compared to previous year
1
3
This is a fork of mariohmol's ang-jsoneditor with support for Angular 16. This repository will probably become stale, when the original will be actively maintained again.
Angular wrapper for jsoneditor). A library with that you can view and edit json content interactively.
The wrapped library is not packaged in this library.
You have to install it via
npm i jsoneditor@9.7
To install this library with npm, run one of the command below:
Compatibility | Command | Stability |
---|---|---|
Angular 11 | npm install @maaxgr/ang-jsoneditor@11 | Stable |
Angular 12 | npm install @maaxgr/ang-jsoneditor@12 | Stable |
Angular 13 | npm install @maaxgr/ang-jsoneditor@13 | Stable |
Angular 14 | npm install @maaxgr/ang-jsoneditor@14 | Stable |
Angular 14 | npm install ngx-json-builder@16 | Stable |
WARNING: Although versions are marked as stable, there can be still bugs because this project isn't heavily integrated in a lot of production projects
First import Module in module.ts:
1// For Angular 11 + 12 2import { NgJsonEditorModule } from 'ngx-json-builder' 3// Starting Angular 13 4import { NgxJsonBuilderModule } from 'ngx-json-builder' 5 6@NgModule({ 7 declarations: [ 8 AppComponent 9 ], 10 imports: [ 11 ...., 12 // For Angular 11 + 12 13 NgJsonEditorModule, 14 // Starting Angular 13 15 NgxJsonBuilderModule, 16 ], 17 providers: [], 18 bootstrap: [AppComponent] 19}) 20export class AppModule { }
Then setup your component models as below:
1import {Component} from '@angular/core'; 2import {JsonEditorOptions} from "ngx-json-builder"; 3 4@Component({ 5 selector: 'app-root', 6 template: '<json-editor [options]="editorOptions" [data]="initialData" (change)="showJson($event)"></json-editor>' + 7 '<div>{{ visibleData | json }}</div>' 8}) 9export class AppComponent { 10 11 public editorOptions: JsonEditorOptions; 12 public initialData: any; 13 public visibleData: any; 14 15 constructor() { 16 this.editorOptions = new JsonEditorOptions() 17 this.editorOptions.modes = ['code', 'text', 'tree', 'view']; 18 19 this.initialData = {"products":[{"name":"car","product":[{"name":"honda","model":[{"id":"civic","name":"civic"},{"id":"accord","name":"accord"},{"id":"crv","name":"crv"},{"id":"pilot","name":"pilot"},{"id":"odyssey","name":"odyssey"}]}]}]} 20 this.visibleData = this.initialData; 21 } 22 23 showJson(d: Event) { 24 this.visibleData = d; 25 } 26 27}
Add Style to style.scss:
1@import "~jsoneditor/dist/jsoneditor.min.css";
For deeper configuration, add this to component.ts:
1@ViewChild(JsonEditorComponent, { static: false }) editor!: JsonEditorComponent;
Build it integrated with ReactiveForms:
1this.form = this.fb.group({ 2 myinput: [this.data] 3});
1<form [formGroup]="form" (submit)="submit()"> 2 <json-editor [options]="editorOptions2" formControlName="myinput"> 3 </json-editor> 4</form>
Besides all the configuration options from the original jsoneditor, Angular Json Editor supports one additional option:
=> expandAll
: to automatically expand all nodes upon json loaded with the data input.
If you have issue with the height of the component, you can try one of those solutions:
When you import CSS:
1@import "~jsoneditor/dist/jsoneditor.min.css"; 2textarea.jsoneditor-text{min-height:350px;}
Or Customizing the CSS:
1:host ::ng-deep json-editor, 2:host ::ng-deep json-editor .jsoneditor, 3:host ::ng-deep json-editor > div, 4:host ::ng-deep json-editor jsoneditor-outer { 5 height: 500px; 6}
Or as a inner style in component:
1<json-editor class="col-md-12" #editorExample style="min-height: 300px;" [options]="editorOptionsData" [data]="dataStructure"></json-editor>
For code view you can change the height using this example:
1.ace_editor.ace-jsoneditor { 2 min-height: 500px; 3}
Use debug mode to see in your console the data and options passed to jsoneditor. Copy this and paste in your issue when reporting bugs.
1<json-editor [debug]="true" [options]="editorOptionsData" [data]="dataStructure"></json-editor>
If you find youself trying to use an custom option that is not mapped here, you can do:
1let editorOptions: JsonEditorOptions = new JsonEditorOptions(); (<any>this.editorOptions).templates = [{menu options objects as in json editor documentation}]
See the issue
If you want to support IE, please follow this guide:
To use multiple jsoneditors in your view you cannot use the same editor options.
You should have something like:
1<div *ngFor="let prd of data.products" class="w-100-p p-24" > 2 <json-editor [options]="makeOptions()" [data]="prd" (change)="showJson($event)"></json-editor> 3</div>
1makeOptions = () => { 2 return new JsonEditorOptions(); 3}
Demo component files are included in Git Project under projects/demo
.
An explanation how to start the demo is in the Local Development-Guide
No vulnerabilities found.
No security vulnerabilities found.