From 37c51cee299efb2f495626cb72104b022627aa87 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 24 Jul 2024 18:22:19 -0400 Subject: [PATCH] Now with JSON validity checking. Done for the day. --- src/routes/core/person_view.svelte | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/routes/core/person_view.svelte b/src/routes/core/person_view.svelte index 3c420e85..58216c38 100644 --- a/src/routes/core/person_view.svelte +++ b/src/routes/core/person_view.svelte @@ -43,6 +43,19 @@ $: if ($lq__person_obj?.data_json && ae_tmp.value__data_json === null) { // JSON.stringify(jsObj, null, 4); } +ae_tmp.valid__data_json = null; +$: if (ae_tmp.value__data_json && ae_tmp.value__data_json.length) { + console.log(`ae_tmp.value__data_json.length:`, ae_tmp.value__data_json.length); + + try { + JSON.parse(ae_tmp.value__data_json); + ae_tmp.valid__data_json = true; + } catch (e) { + ae_tmp.valid__data_json = false; + console.error(`JSON.parse error:`, e); + } +} + // $events_slct.person_obj = $lq__person_obj; @@ -553,13 +566,22 @@ onMount(() => { -

JSON length: {(ae_tmp.value__data_json ? ae_util.number_w_commas(ae_tmp.value__data_json.length) : 0)} characters

+

+ JSON length: {(ae_tmp.value__data_json ? ae_util.number_w_commas(ae_tmp.value__data_json.length) : 0)} characters + + {#if ae_tmp.valid__data_json} + + {:else} + + Invalid JSON + {/if} +