Skip to content

Commit

Permalink
fix(json): handle parsed content (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Aug 16, 2022
1 parent 19fae5d commit 6aad636
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/runtime/transformers/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default defineTransformer({
} else if (_id.endsWith('json')) {
parsed = destr(content)
}
} else {
parsed = content
}

// Keep array contents under `body` key
Expand Down
6 changes: 6 additions & 0 deletions test/features/parser-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export const testJSONParser = () => {
expect(parsed.body).toHaveLength(2)
expect(parsed.body).toMatchObject(['item 1', 'item 2'])
})

test('unstorage json', async () => {
const parsed = await $fetch('/_partial/simple-json')

expect(parsed).contains('"test": "test content"')
})
})

describe('parser:json5', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/basic/content/_partial/simple-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": "test content"
}

0 comments on commit 6aad636

Please sign in to comment.