mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Recovery option for jsonParse helper (#10182)
Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
@@ -145,10 +145,14 @@ describe('Type Validation', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should validate and cast JSON properly', () => {
|
||||
it('should validate and cast JSON & JS objects properly', () => {
|
||||
const VALID_OBJECTS = [
|
||||
['{"a": 1}', { a: 1 }],
|
||||
['{a: 1}', { a: 1 }],
|
||||
["{'a': '1'}", { a: '1' }],
|
||||
["{'\\'single quoted\\' \"double quoted\"': 1}", { '\'single quoted\' "double quoted"': 1 }],
|
||||
['{"a": 1, "b": { "c": 10, "d": "test"}}', { a: 1, b: { c: 10, d: 'test' } }],
|
||||
["{\"a\": 1, b: { 'c': 10, d: 'test'}}", { a: 1, b: { c: 10, d: 'test' } }],
|
||||
[{ name: 'John' }, { name: 'John' }],
|
||||
[
|
||||
{ name: 'John', address: { street: 'Via Roma', city: 'Milano' } },
|
||||
@@ -162,19 +166,18 @@ describe('Type Validation', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const INVALID_JSON = [
|
||||
const INVALID_OBJECTS = [
|
||||
['one', 'two'],
|
||||
'1',
|
||||
'[1]',
|
||||
'1.1',
|
||||
1.1,
|
||||
'"a"',
|
||||
'{a: 1}',
|
||||
'["apples", "oranges"]',
|
||||
[{ name: 'john' }, { name: 'bob' }],
|
||||
'[ { name: "john" }, { name: "bob" } ]',
|
||||
];
|
||||
INVALID_JSON.forEach((value) =>
|
||||
INVALID_OBJECTS.forEach((value) =>
|
||||
expect(validateFieldType('json', value, 'object').valid).toEqual(false),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user