Skip to content

Commit 5235a9f

Browse files
committed
Json date support
1 parent 81493e6 commit 5235a9f

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/components/Json/Json.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ describe('Json Component', () => {
5555
getByText('"value"')
5656
})
5757

58+
it('renders a Date as its ISO string', () => {
59+
const { getByText } = render(<Json json={new Date('2025-01-01')} />)
60+
getByText('"2025-01-01T00:00:00.000Z"')
61+
})
62+
5863
it('renders nested objects', () => {
5964
const { getByText } = render(<Json json={{ obj: { arr: [314, '42'] } }} />)
6065
getByText('obj:')

src/components/Json/Json.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function JsonContent({ json, label, expandRoot, pageLimit }: JsonProps): ReactNo
2727
let div
2828
if (Array.isArray(json)) {
2929
div = <JsonArray array={json} label={label} expandRoot={expandRoot} pageLimit={pageLimit} />
30+
} else if (json instanceof Date) {
31+
const key = label ? <span className={styles.key}>{label}: </span> : ''
32+
div = <>{key}<span className={styles.string}>{JSON.stringify(json)}</span></>
3033
} else if (typeof json === 'object' && json !== null) {
3134
div = <JsonObject label={label} obj={json} expandRoot={expandRoot} pageLimit={pageLimit} />
3235
} else {

0 commit comments

Comments
 (0)