Skip to content

Commit 6aad636

Browse files
authored
fix(json): handle parsed content (#1437)
1 parent 19fae5d commit 6aad636

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/runtime/transformers/json.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export default defineTransformer({
1515
} else if (_id.endsWith('json')) {
1616
parsed = destr(content)
1717
}
18+
} else {
19+
parsed = content
1820
}
1921

2022
// Keep array contents under `body` key

test/features/parser-json.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export const testJSONParser = () => {
5555
expect(parsed.body).toHaveLength(2)
5656
expect(parsed.body).toMatchObject(['item 1', 'item 2'])
5757
})
58+
59+
test('unstorage json', async () => {
60+
const parsed = await $fetch('/_partial/simple-json')
61+
62+
expect(parsed).contains('"test": "test content"')
63+
})
5864
})
5965

6066
describe('parser:json5', () => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"test": "test content"
3+
}

0 commit comments

Comments
 (0)