diff --git a/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts b/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts index ff8d2adead..7ef523e7d0 100644 --- a/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts +++ b/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts @@ -26,6 +26,7 @@ import { Validator } from '@angular/forms'; import { ErrorStateMatcher } from '@angular/material/core'; +import { isObject } from "@core/utils"; @Directive({ selector: '[tb-json-to-string]', @@ -53,7 +54,11 @@ export class TbJsonToStringDirective implements ControlValueAccessor, Validator, @HostListener('input', ['$event.target.value']) input(newValue: any): void { try { this.data = JSON.parse(newValue); - this.parseError = false; + if (isObject(this.data)) { + this.parseError = false; + } else { + this.parseError = true; + } } catch (e) { this.parseError = true; } diff --git a/ui-ngx/src/app/shared/components/json-object-edit.component.ts b/ui-ngx/src/app/shared/components/json-object-edit.component.ts index e7a1b97cad..919dbace34 100644 --- a/ui-ngx/src/app/shared/components/json-object-edit.component.ts +++ b/ui-ngx/src/app/shared/components/json-object-edit.component.ts @@ -22,7 +22,7 @@ import { ActionNotificationHide, ActionNotificationShow } from '@core/notificati import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; -import { guid, isDefinedAndNotNull, isLiteralObject, isUndefined } from '@core/utils'; +import { guid, isDefinedAndNotNull, isObject, isUndefined } from '@core/utils'; import { ResizeObserver } from '@juggle/resize-observer'; import { getAce } from '@shared/models/ace/ace.models'; @@ -259,7 +259,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va if (this.contentValue && this.contentValue.length > 0) { try { data = JSON.parse(this.contentValue); - if (!isLiteralObject(data)) { + if (!isObject(data)) { throw new TypeError(`Value is not a valid JSON`); } this.objectValid = true; diff --git a/ui-ngx/src/app/shared/models/constants.ts b/ui-ngx/src/app/shared/models/constants.ts index 2a01a7eae4..37027edc68 100644 --- a/ui-ngx/src/app/shared/models/constants.ts +++ b/ui-ngx/src/app/shared/models/constants.ts @@ -202,7 +202,7 @@ export const valueTypesMap = new Map( ValueType.JSON, { name: 'value.json', - icon: 'mdi:json' + icon: 'mdi:code-json' } ] ]