json view

This commit is contained in:
Jan Prochazka
2021-04-03 18:52:11 +02:00
parent 18860c823d
commit 41cf7009b3
4 changed files with 38 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
<script lang="ts">
import _ from 'lodash';
import JSONTree from 'svelte-json-tree';
import ErrorInfo from '../elements/ErrorInfo.svelte';
@@ -8,7 +9,8 @@
let error = null;
$: try {
json = JSON.parse(selection[0].value);
const value = selection[0].value;
json = _.isPlainObject(value) || _.isArray(value) ? value : JSON.parse(value);
error = null;
} catch (err) {
error = err.message;
@@ -16,7 +18,7 @@
</script>
{#if error}
<ErrorInfo message="Error parsing JSON" />
<ErrorInfo message="Error parsing JSON" alignTop />
{:else}
<div class="outer">
<div class="inner">