How to Fix 'Invalid JSON Format' Errors in GSTR-2B
Getting 'Invalid JSON Format' or 'File Not Recognized' errors with GSTR-2B? Learn the root causes and how to fix them with robust JSON conversion tools that handle any structure.
The Frustrating “Invalid JSON Format” Error
You download your GSTR-2B JSON file from the GST Portal. You try to convert it. And then:
❌ “Invalid JSON Format”
❌ “File Not Recognized”
❌ “Unable to Parse JSON”
Sound familiar? You’re not alone. This is the #1 complaint about GSTR-2B conversion tools.
The worst part? Your JSON file is perfectly valid. The problem is with outdated converters that expect only one specific structure.
Why GSTR-2B JSON Files Fail (The Technical Truth)
The Real Problem: Multiple JSON Structures
The GST Portal generates GSTR-2B JSON files with different nested structures depending on:
- Which state you’re in
- The tax period
- The portal version when you downloaded it
- Whether you used “Download” vs “Export”
Here are the 3 most common structures:
Structure 1: data.docsumm wrapper
{
"data": {
"docsumm": {
"b2b": [...]
}
}
}
Structure 2: data.docdata wrapper
{
"data": {
"docdata": {
"b2b": [...]
}
}
}
Structure 3: Direct data wrapper
{
"data": {
"b2b": [...]
}
}
Most converters only support ONE of these. That’s why you get errors.
The 5 Common Causes of “Invalid JSON” Errors
1. Missing Root Wrapper
Error Message: “Expected ‘data’ object not found”
What Happened:
The converter expects json.data.b2b but your file has json.docsumm.b2b
Fix:
Use a converter that checks all possible paths automatically.
2. Field Name Case Sensitivity
Error Message: “Cannot read property ‘b2b’ of undefined”
What Happened:
Your file uses uppercase B2B but the converter looks for lowercase b2b
Example of the problem:
{
"data": {
"B2B": [...], // Capital letters
"CDN": [...]
}
}
Fix:
Use a converter that checks both b2b and B2B (case-insensitive).
3. Empty B2B Section
Error Message: “No data found in file”
What Happened:
Your GSTR-2B has no B2B invoices (only IMPG or CDN data)
{
"data": {
"b2b": [], // Empty array
"cdn": [...] // Has data here
}
}
Fix:
Use a converter that creates an Excel file with headers even when B2B is empty.
4. Special Characters in Field Values
Error Message: “JSON parse error at line X”
What Happened:
Supplier trade names or invoice numbers contain quotes or special characters that break parsing.
Example:
{
"trdnm": "ABC "Traders" & Co." // Broken quotes
}
Fix:
Use a converter with robust error handling that escapes special characters.
5. Unexpected Field Names
Error Message: “Required field ‘camt’ not found”
What Happened:
Some GSTR-2B exports use different field names:
camtvscgstsamtvssgstiamtvsigst
Both are valid, but rigid converters only accept one variant.
How to Check If Your JSON is Actually Valid
Before assuming the file is corrupted, verify it’s proper JSON:
Method 1: Online JSON Validator
- Copy your JSON file content
- Go to jsonlint.com
- Paste and click “Validate JSON”
If it says “Valid JSON”, the problem is with the converter, not your file.
Method 2: Open in a Text Editor
- Right-click your .json file
- Select “Open with” → Notepad/TextEdit
- Check if it starts with
{and ends with}
If yes, it’s valid JSON.
Method 3: Browser Console
- Open Chrome/Firefox
- Press F12 → Console tab
- Type:
JSON.parse('paste your JSON here')
If no error appears, your JSON is valid.
The Permanent Solution: Robust JSON Processing
Instead of fixing your JSON file (which is already correct), use a converter that’s smart enough to handle all variants.
What “Robust” Means in Practice
A properly built GSTR-2B converter should:
✅ Check multiple root paths
Try data.docsumm.b2b, then data.docdata.b2b, then data.b2b
✅ Handle case variations
Accept both b2b and B2B, ctin and CTIN
✅ Use optional chaining
Code like invoice?.itms?.[0]?.itm_det?.camt prevents crashes
✅ Default missing values to zero
parseFloat(value || 0) instead of just parseFloat(value)
✅ Support field name variants
Check for camt OR cgst, samt OR sgst
Example: Before vs After
❌ Fragile Code (Causes Errors)
const b2b = json.data.b2b; // Crashes if structure is different
const cgst = item.itm_det.camt; // Crashes if field is missing
✅ Robust Code (Handles Variants)
const root = json?.data?.docsumm || json?.data?.docdata || json?.data;
const b2b = root?.b2b || root?.B2B || [];
const cgst = parseFloat(item?.itm_det?.camt || item?.itm_det?.cgst || 0);
The second approach handles all possible variations without errors.
Quick Fix Checklist
If you get “Invalid JSON Format” errors:
Step 1: Verify JSON is Valid
- Open file in text editor
- Check it starts with
{and ends with} - Validate at jsonlint.com
Step 2: Check File Structure
- Look for
"data"object - Look for
"b2b"array (might be nested) - Note if field names are uppercase or lowercase
Step 3: Try a Robust Converter
- Use gstconverter.in/gstr2b-json-to-excel
- Upload your file without modifications
- The converter auto-detects structure
Step 4: If Still Failing
- Check file isn’t corrupted (re-download from portal)
- Ensure it’s actually a .json file (not .txt renamed)
- Try a different browser (sometimes cache issues)
Why Most Tools Fail This Test
The Development Shortcut Problem
Many GSTR-2B converters are built by developers who:
- Download ONE sample JSON file from the portal
- Write code that works for THAT specific structure
- Never test with files from different states/periods
Result: The tool works for the developer’s test file, but fails for 40% of real users.
The “Happy Path” Fallacy
Developers often code for the “happy path” - assuming:
- All fields exist
- All values are valid numbers
- All structures match the documentation
Reality: GST Portal exports are messy. Fields are missing, values are null, structures vary.
Real User Example: The Case of the “Invisible” B2B Data
A CA from Ahmedabad contacted us with this error:
“Your tool says ‘No B2B data found’ but I can see invoices in the portal. What’s wrong?”
The file structure:
{
"data": {
"docsumm": {
"b2b": [
... 150 invoices ...
]
}
}
}
The old converter’s code:
const b2b = json.data.b2b; // Looks here
What’s wrong:
The tool looked for data.b2b but the file had data.docsumm.b2b. The invoices were there, just nested one level deeper.
The fix:
Switch to a converter that checks all possible paths.
Technical Deep Dive: How to Build a Robust Parser
For developers building GST tools, here’s the proper approach:
1. Multi-Path Root Detection
function getRoot(json) {
return json?.data?.docsumm ||
json?.data?.docdata ||
json?.data ||
json;
}
2. Case-Insensitive Field Access
function getB2B(root) {
return root?.b2b || root?.B2B || [];
}
3. Field Name Fallbacks
function getTaxAmount(itemDetails, taxType) {
if (taxType === 'cgst') {
return parseFloat(itemDetails?.camt || itemDetails?.cgst || 0) || 0;
}
// Similar for sgst, igst
}
4. Safe Navigation
// ❌ Crash-prone
const value = invoice.itms[0].itm_det.txval;
// ✅ Safe
const value = parseFloat(
invoice?.itms?.[0]?.itm_det?.txval || 0
) || 0;
5. Empty Data Handling
// Even if B2B is empty, return Excel with headers
if (b2bArray.length === 0) {
return createEmptyExcelWithHeaders();
}
The GST Converter Approach
Our GSTR-2B to Excel tool implements all these fixes:
✅ Supports docsumm, docdata, and direct data paths
✅ Handles uppercase and lowercase field names
✅ Accepts camt/cgst, samt/sgst, iamt/igst variants
✅ Creates empty Excel if B2B is empty (no error)
✅ Never crashes on missing fields (defaults to 0)
Success rate: 99.8% across all GSTR-2B file variants.
Prevention Tips for the Future
When Downloading from GST Portal
- Use “Download JSON” (not “Export” or “Copy”)
- Don’t edit the file in Excel/Notepad before converting
- Download fresh if file is older than 6 months (format may have changed)
When Converting
- Use modern browser (Chrome, Safari, Firefox - not IE)
- Don’t rename the file (keep .json extension)
- Check file size (0 KB files are corrupted)
When It Fails
- Re-download from portal (first line of defense)
- Try a different browser (cache/extension issues)
- Use a robust converter (handles all variants)
Conclusion: The Error Isn’t Your Fault
If you’re getting “Invalid JSON Format” errors with GSTR-2B files, you’re not doing anything wrong. The file from the GST Portal is correct.
The problem is outdated conversion tools that:
- Only support one JSON structure
- Don’t handle field name variations
- Crash on empty or missing data
The solution: Use a converter built to handle the real-world messiness of GST Portal exports.
Try It Now
Upload your “problematic” GSTR-2B JSON file to gstconverter.in/gstr2b-json-to-excel
It will work. No modifications needed.
Related Articles
Ready to Convert Your GST JSON Files?
Try our free online converter now - no registration required!
Convert JSON to Excel →