diff --git a/packages/core/helper-plugin/lib/src/content-manager/utils/formatContentTypeData.js b/packages/core/helper-plugin/lib/src/content-manager/utils/formatContentTypeData.js index 38c0d739f9..08a64513ad 100644 --- a/packages/core/helper-plugin/lib/src/content-manager/utils/formatContentTypeData.js +++ b/packages/core/helper-plugin/lib/src/content-manager/utils/formatContentTypeData.js @@ -12,14 +12,14 @@ const formatContentTypeData = (data, ct, composSchema) => { const compoUid = getOtherInfos(schema, [current, 'component']); const isRepeatable = getOtherInfos(schema, [current, 'repeatable']); - if (!value) { - acc[current] = value; + if (type === 'json' && value !== undefined) { + acc[current] = JSON.stringify(value, null, 2); return acc; } - if (type === 'json') { - acc[current] = JSON.stringify(value, null, 2); + if (!value) { + acc[current] = value; return acc; } diff --git a/packages/core/helper-plugin/lib/src/content-manager/utils/tests/formatContentTypeData.test.js b/packages/core/helper-plugin/lib/src/content-manager/utils/tests/formatContentTypeData.test.js index 836f8b6960..d78b048517 100644 --- a/packages/core/helper-plugin/lib/src/content-manager/utils/tests/formatContentTypeData.test.js +++ b/packages/core/helper-plugin/lib/src/content-manager/utils/tests/formatContentTypeData.test.js @@ -87,6 +87,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => { dz: { type: 'dynamiczone', components: ['compos.sub-compo'] }, jsonString: { type: 'json' }, jsonObject: { type: 'json' }, + jsonBool: { type: 'json' }, }, }; @@ -119,6 +120,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => { ], jsonString: 'hello', jsonObject: { hello: true }, + jsonBool: false, }; const expected = { @@ -136,6 +138,7 @@ describe('STRAPI_HELPER_PLUGIN | utils | formatContentTypeData', () => { ], jsonString: '"hello"', jsonObject: '{\n "hello": true\n}', + jsonBool: 'false', }; expect(formatContentTypeData(data, contentType, components)).toEqual(expected);