Rescue Unsafe Long JSON Integers Before Parsing
Loading workflow…
Workflow Description
A self-contained workflow that treats JSON as raw text before parsing. A Code node scans character by character, tracking string state and escape sequences, applies JSON number grammar, and compares every bare decimal integer against the safe Number range using BigInt. Unsafe integers are replaced by JSON strings carrying the identical digits; fractions and exponents stay untouched but are logged as warnings. The protected text is then parsed inside try/catch, an IF node routes success and failure, and a final Code node emits protectedJson, parsedValue, conversions and warnings per record.
How it works
- 1.Manual Trigger fires the workflow with a single empty item.
- 2.A Code node emits three fictional payloads with recordId and rawJson fields.
- 3.The scanner Code node tracks strings and escapes, quotes unsafe integers and records their original digits and start index.
- 4.JSON.parse runs on the protected text inside try/catch, producing parseOk and parseError.
- 5.The IF node routes parseOk=true to a success Set and parseOk=false to a failure Set plus NoOp.
- 6.Merge (append) joins both branches and a final Code node normalises field order, one output item per record.
Use cases
- Receiving long identifiers (Snowflake IDs, sequence numbers) as raw text without precision loss.
- Sanitising webhook payloads before downstream nodes consume them.
- Diagnosing which numbers exceed the safe integer range and where they occur.
- Explicitly rejecting invalid payloads instead of claiming a safe object.
Requirements
- n8n 2.48.8 with core nodes only; no credentials needed.
- A string field rawJson containing raw, not-yet-parsed JSON.
- A Code environment supporting BigInt (BigInt itself is never emitted).
- Agreement that unsafe integers become strings in the resulting object.
Setup and testing in n8n
- Import the JSON, open the workflow and click Execute Workflow.
- Check record one: two conversions at indexes 6 and 53 plus two warnings for the fraction and exponent.
- Check record two: no conversions, since the digits sit inside a string after an escape sequence.
- Check record three: status=failed, parsedValue=null and a local parse error message.
- Add an item containing 9007199254740991 and confirm it stays a number, then send an empty rawJson to see the missing-input message.
- Replace the sample node with a real source returning raw text mapped to the same rawJson field.
Service Value
Ready-made workflow template for automation delivery and service execution.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (9)
Manual Trigger
Manual Trigger
Sample Raw JSON Payloads
Code
Quote Unsafe Integers And Parse
Code
Parsed Successfully?
If
Mark Safe Payload
Set
Mark Failed Payload
Set
No Safe Object Produced
No Op
Merge Branches
Merge
Build Rescue Report
Code
Note Input
Sticky Note
Note Scanner
Sticky Note
Note Routing
Sticky Note
Fresh workflows, straight to your inbox
Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.
- New workflows
- Clear overviews
- Setup guides