Azure DevOps throwing "Unexpected token < in JSON at position 4"

Azure DevOps throwing “Unexpected token < in JSON at position 4"?

4 min read.

This article documents one of the simplest solutions to one of the simplest issues you might ever encounter with Azure DevOps. Still: it’s a pretty annoying one, and the solution – as simple as it is – seems worth documenting for the next time I’m googling this fervently as I’m afraid of losing my unsaved changes again… :)

Essentially, your editor view in Azure DevOps times out and you risk losing any changes you’ve done, and it’s all due to clumsy authentication implementation by Microsoft. But it’s easy to work around – it’s just one of those simple gotchas that you just kind of need to know.

Problem

Table of Contents

So what was the issue, again?

Let’s presume you’re modifying a work item, or maybe a build definition in Azure DevOps using your favorite web browser. But suddenly, when you click “save”, or maybe “refresh”, you get a pop-up / alert window showing an issue like this:

"Unexpected token < in JSON at position 4"

You might also find it from your browser console, or shown in a red box above your editor window. And in some views, puzzlingly enough, you might get this error (the problem being the same, just the symptom differs):

203: ParseError

What gives?

Reason

When you observe the requests in your browser’s console a little bit closer, the reason becomes pretty clear.

Look at the code below – the character at position 4, which is actually the first character on LINE 4, is indeed <. And the page it represents asks you to sign in :)

Expand the whole html by clicking this (it's pretty long!)



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    
    

<html lang="en-US">
<head><title>
	
            Azure DevOps Services | Sign In
        
</title><meta http-equiv="X-UA-Compatible" content="IE=11;&#32;IE=10;&#32;IE=9;&#32;IE=8" />
    <link rel="SHORTCUT ICON" href="/favicon.ico"/>

    <link data-bundlelength="508992" data-bundlename="commoncss" data-highcontrast="/_static/tfs/M186_20210428.6/_cssbundles/HighContrast/vss-bundle-commoncss-v6u3Ge4AQ3uP84WaM1_W6QGvjulv0ohK4twlMPGNhjUY=" data-includedstyles="jQueryUI-Modified;Core;Splitter;PivotView" href="/_static/tfs/M186_20210428.6/_cssbundles/Default/vss-bundle-commoncss-vHQmPgPp5spmzbH-BlYoXG_Hn35TPVL28elmFhmVVmDU=" rel="stylesheet" />
<link data-bundlelength="116298" data-bundlename="viewcss" data-highcontrast="/_static/tfs/M186_20210428.6/_cssbundles/HighContrast/vss-bundle-viewcss-vtfMnrmJMJV2boj-Fa92RIMxY_zlsBBPAdos3V1rIXA4=" data-includedstyles="VSS.Controls" href="/_static/tfs/M186_20210428.6/_cssbundles/Default/vss-bundle-viewcss-v9YWu-gu1EsBKWCVDchwAqVtMik782dp5J3eM8pJXNoY=" rel="stylesheet" />

    <!--UxServices customizations -->
    
    <link href="/_static/tfs/M186_20210428.6/_content/Authentication.css" type="text/css" rel="stylesheet" />
    
</head>

<body class="platform">

    <script type="text/javascript"> var __vssPageContext = {"webContext":{"user":{"id":"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa","name":"Anonymous","email":"","uniqueName":"TEAM FOUNDATION\\Anonymous"},"host":{"id":"7d0cc8e9-39e8-4313-9ff3-23ace0f8f4cf","name":"TEAM FOUNDATION","uri":"https://spsprodweu4.vssps.visualstudio.com/","relativeUri":"/","hostType":"deployment","scheme":"https","authority":"spsprodweu4.vssps.visualstudio.com"}},"moduleLoaderConfig":{"baseUrl":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/","paths":{"Profile/Scripts/Resources":"en-US","VSS/Resources":"en-US","Account/Scripts/Resources":"en-US","UserManagement/Scripts/Resources":"en-US","Authentication/Scripts/Resources":"en-US"},"map":{},"contributionPaths":{"VSS":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/VSS","pathType":"default"},"VSS/Resources":{"value":"en-US","pathType":"resource"},"q":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/q","pathType":"default"},"knockout":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/knockout","pathType":"default"},"mousetrap":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/mousetrap","pathType":"default"},"mustache":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/mustache","pathType":"default"},"react":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/react.15.3","pathType":"default"},"react-dom":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/react-dom.15.3","pathType":"default"},"react-transition-group":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/react-transition-group.15.3","pathType":"default"},"jQueryUI":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/jQueryUI","pathType":"default"},"jquery":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/jquery","pathType":"default"},"OfficeFabric":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/OfficeFabric","pathType":"default"},"tslib":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/tslib","pathType":"default"},"@uifabric":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/@uifabric","pathType":"default"},"VSSUI":{"value":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/VSSUI","pathType":"default"}},"shim":{"jquery":{"deps":[],"exports":"jQuery"}},"waitSeconds":30},"coreReferences":{"stylesheets":[{"url":"/_static/tfs/M186_20210428.6/_cssbundles/Default/vss-bundle-ext-core-css-vNmgDWCLCX0sHlt44FFqt9QrKVBLhz4rqsgP12zXSp8g=","highContrastUrl":null,"isCoreStylesheet":true}],"scripts":[{"identifier":"JQuery","url":"/_static/3rdParty/_scripts/jquery-2.2.4.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"JQueryXDomain","url":"/_static/3rdParty/_scripts/jquery.xdomainrequest.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"Promise","url":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/promise.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"GlobalScripts","url":"/_static/tfs/M186_20210428.6/_scripts/TFS/min/global-scripts.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"LoaderFixes","url":"/_static/tfs/M186_20210428.6/_scripts/TFS/pre-loader-shim.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":false},{"identifier":"AMDLoader","url":"/_static/3rdParty/_scripts/require.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"LoaderFixes","url":"/_static/tfs/M186_20210428.6/_scripts/TFS/post-loader-shim.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":false}],"coreScriptsBundle":{"identifier":"CoreBundle","url":"/_public/_Bundling/Content?bundle=vss-bundle-basejs-v9GpWWBnsWqhM23ijhK2HfAqLowTXGUqZLDRsBCZbkfY=","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},"extensionCoreReferences":{"identifier":"CoreBundle","url":"/_public/_Bundling/Content?bundle=vss-bundle-ext-core-vIzSYLPJCTdYZH2THb6MmQ8IGqUykR9674vJI83Yv4xM=","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true}},"webAccessConfiguration":{"isHosted":true,"paths":{"rootPath":"/","staticContentRootPath":"/","staticContentVersion":"M186_20210428.6","resourcesPath":"/_static/tfs/M186_20210428.6/_content/","staticRootTfs":"/_static/tfs/M186_20210428.6/","cdnFallbackStaticRootTfs":"/_static/tfs/M186_20210428.6/","staticRoot3rdParty":"/_static/3rdParty/"},"api":{"webApiVersion":"1","areaPrefix":"_","controllerPrefix":""},"mailSettings":{"enabled":false},"registryItems":{}},"microsoftAjaxConfig":{"cultureInfo":{"name":"en-US","numberFormat":{"CurrencyDecimalDigits":2,"CurrencyDecimalSeparator":".","IsReadOnly":true,"CurrencyGroupSizes":[3],"NumberGroupSizes":[3],"PercentGroupSizes":[3],"CurrencyGroupSeparator":",","CurrencySymbol":"$","NaNSymbol":"NaN","CurrencyNegativePattern":0,"NumberNegativePattern":1,"PercentPositivePattern":1,"PercentNegativePattern":1,"NegativeInfinitySymbol":"-∞","NegativeSign":"-","NumberDecimalDigits":2,"NumberDecimalSeparator":".","NumberGroupSeparator":",","CurrencyPositivePattern":0,"PositiveInfinitySymbol":"∞","PositiveSign":"+","PercentDecimalDigits":2,"PercentDecimalSeparator":".","PercentGroupSeparator":",","PercentSymbol":"%","PerMilleSymbol":"‰","NativeDigits":["0","1","2","3","4","5","6","7","8","9"],"DigitSubstitution":1},"dateTimeFormat":{"AMDesignator":"AM","Calendar":{"MinSupportedDateTime":"0001-01-01T00:00:00","MaxSupportedDateTime":"9999-12-31T23:59:59.9999999","AlgorithmType":1,"CalendarType":1,"Eras":[1],"TwoDigitYearMax":2029,"IsReadOnly":true},"DateSeparator":"/","FirstDayOfWeek":0,"CalendarWeekRule":0,"FullDateTimePattern":"dddd, MMMM d, yyyy h:mm:ss tt","LongDatePattern":"dddd, MMMM d, yyyy","LongTimePattern":"h:mm:ss tt","MonthDayPattern":"MMMM d","PMDesignator":"PM","RFC1123Pattern":"ddd, dd MMM yyyy HH':'mm':'ss 'GMT'","ShortDatePattern":"M/d/yyyy","ShortTimePattern":"h:mm tt","SortableDateTimePattern":"yyyy'-'MM'-'dd'T'HH':'mm':'ss","TimeSeparator":":","UniversalSortableDateTimePattern":"yyyy'-'MM'-'dd HH':'mm':'ss'Z'","YearMonthPattern":"MMMM yyyy","AbbreviatedDayNames":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"ShortestDayNames":["Su","Mo","Tu","We","Th","Fr","Sa"],"DayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"AbbreviatedMonthNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthNames":["January","February","March","April","May","June","July","August","September","October","November","December",""],"IsReadOnly":true,"NativeCalendarName":"Gregorian Calendar","AbbreviatedMonthGenitiveNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthGenitiveNames":["January","February","March","April","May","June","July","August","September","October","November","December",""]},"numberShortForm":{"QuantitySymbols":["K","M","B"],"NumberGroupSize":1000,"ThousandSymbol":"K"},"eras":null}},"timeZonesConfiguration":{},"featureAvailability":{"featureStates":{"VisualStudio.Services.Contribution.EnableOnPremUnsecureBrowsers":false,"VisualStudio.Service.WebPlatform.ClientErrorReporting":false,"Microsoft.VisualStudio.Services.Gallery.Client.UseCdnAssetUri":false,"VisualStudio.Services.WebAccess.SubresourceIntegrity":false,"VisualStudio.Services.IdentityPicker.ReactProfileCard":true}},"appInsightsConfiguration":{"enabled":false,"instrumentationKey":"00000000-0000-0000-0000-000000000000","insightsScriptUrl":null},"diagnostics":{"sessionId":"c6be703a-09c1-4f80-9632-c7e426e62642","activityId":"b62c3e36-d20d-46c7-9373-bedde3f80ff5","bundlingEnabled":true,"webPlatformVersion":"M186","serviceVersion":"Dev18.M186.1 (build: AzureDevOps_M186_20210428.6)"},"navigation":{"topMostLevel":"deployment","area":"","currentController":"Signin","currentAction":"Index","routeId":"LegacyWebAccessRoute","routeValues":{"controller":"Signin","action":"Index"}},"globalization":{"explicitTheme":"","theme":"Default","culture":"en-US","timezoneOffset":0,"timeZoneId":"UTC"},"serviceInstanceId":"951917ac-a960-4999-8464-e3f0aa25b381","hubsContext":{},"serviceLocations":{"locations":{"951917ac-a960-4999-8464-e3f0aa25b381":{"Application":"https://spsprodweu4.vssps.visualstudio.com/","Deployment":"https://spsprodweu4.vssps.visualstudio.com/"}}}};</script><script type="text/javascript"> var __cultureInfo = __vssPageContext.microsoftAjaxConfig.cultureInfo;</script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-basejs'); }</script>
<script data-bundlelength="125076" data-bundlename="basejs" src="/_public/_Bundling/Content?bundle=vss-bundle-basejs-v9GpWWBnsWqhM23ijhK2HfAqLowTXGUqZLDRsBCZbkfY=" type="text/javascript"></script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-basejs'); }</script>


<script type="text/javascript"> require.config(__vssPageContext.moduleLoaderConfig);</script>

    <input name="__RequestVerificationToken" type="hidden" value="wIECI8kSzBxCfddJjPfJyBuk8mEC6r4wcE4ldJYwsdC6y2WD3RXzAX0xrFK4c9s1FGyhZSV8jobAWhGMHrIfYKKLU0Y1" /><input name="__RequestVerificationToken2" type="hidden" value="__RequestVerificationToken2d3c86740-bf9c-4fd9-825f-512f022c707d" />
    
    


    
    
    <div class="account signin main-container hide">


            <div class="page-content">
                <div class="header-section" role="banner">
                    

                    <link rel="stylesheet" type="text/css" href="/_static/tfs/M186_20210428.6/_content/Combined.css">
                    <div id="ux-header" class="FF ltr vsIntegrate" xmlns="http://www.w3.org/1999/xhtml">
                        <span id="isMobile"></span>
                        <div class="upperBand">
                            <div class="upperBandContent">
                                <div class="left"></div>
                                <div class="right">
                                    <div class="profileImage"></div>

                                    <div id="signIn">
                                        <a class=":SignedOutProfileElement: createProfileLink" href="/go/profile" title="Anonymous">Anonymous</a>
                                        <a class="scarabLink" href="/_signout">Sign out</a>
                                    </div>
                                </div>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="content-section" role="main">
                    
    
            <div class="signin-main-content">
                <noscript>
                    <span class="error">Microsoft Internet Explorer&#39;s Enhanced Security Configuration is currently enabled on your environment. This enhanced level of security prevents our web integration experiences from displaying or performing correctly. To continue with your operation please disable this configuration or contact your administrator.</span>
                </noscript>
                <div class="provider-control">                    
                    <script class="options" defer="defer" type="application/json">{"providerOptions":{"force":true,"orgIdAuthUrl":"https://login.microsoftonline.com/1f23d6d3-b158-4e45-b7e1-7631cf28c804/oauth2/authorize?client_id=499b84ac-1321-427f-aa17-267ca6975798\u0026site_id=501454\u0026response_mode=form_post\u0026response_type=code+id_token\u0026redirect_uri=https%3A%2F%2Fspsprodweu4.vssps.visualstudio.com%2F_signedin\u0026nonce=162fec16-8dbc-4ff6-9b4f-baa785b7fb32\u0026state=realm%3Ddev.azure.com%26reply_to%3Dhttps%253A%252F%252Fdev.azure.com%252Fetteplanmorepyrollgroup%252F_apis%252Fnotification%252FSubscriptionQuery%26ht%3D2%26hid%3D53c552d2-9571-467b-9f96-5a135ef03e9f%26force%3D1%26nonce%3D162fec16-8dbc-4ff6-9b4f-baa785b7fb32\u0026resource=https%3A%2F%2Fmanagement.core.windows.net%2F\u0026cid=162fec16-8dbc-4ff6-9b4f-baa785b7fb32\u0026wsucxt=1\u0026prompt=select_account","user":null,"signInContext":"eyJodCI6MiwiaGlkIjoiMGJhNzNkYmMtOWY2My00MzcwLWE0YWMtN2I5YzgxNmY5Njk0IiwicXMiOnsicmVhbG0iOiJkZXYuYXp1cmUuY29tIiwicmVwbHlfdG8iOiJodHRwczovL2Rldi5henVyZS5jb20vZXR0ZXBsYW5tb3JlcHlyb2xsZ3JvdXAvX2FwaXMvbm90aWZpY2F0aW9uL1N1YnNjcmlwdGlvblF1ZXJ5IiwiaHQiOiIyIiwiaGlkIjoiNTNjNTUyZDItOTU3MS00NjdiLTlmOTYtNWExMzVlZjAzZTlmIiwiZm9yY2UiOiIxIiwibm9uY2UiOiIxNjJmZWMxNi04ZGJjLTRmZjYtOWI0Zi1iYWE3ODViN2ZiMzIifSwicnIiOiIiLCJ2aCI6IiIsImN2IjoiIiwiY3MiOiIifQ2"}}</script>
                </div>
            </div>


                </div>
                 
    
    </div>


    
    

    <script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-common'); }</script>
<script data-bundlelength="212619" data-bundlename="common" data-includedscripts="VSS/Bundling" src="/_public/_Bundling/Content?bundle=vss-bundle-common-v9clbQjZeX8SFazwgF3HBRpCw_AYcSBPxtOpkg9Bv2-o=" type="text/javascript"></script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-common'); }</script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-view'); }</script>
<script data-bundlelength="159354" data-bundlename="view" data-includedscripts="Authentication/Scripts/SPS.Authentication.Controls;Authentication/Scripts/SPS.Authentication" src="/_public/_Bundling/Content?bundle=vss-bundle-view-vNUGsoXgRUC5b3kr3BUOKazaVcS2VmFUCbEtaFD5SGSA=" type="text/javascript"></script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-view'); }</script>

<script type="text/javascript"> if (window.performance && window.performance.mark) { window.performance.mark('requireStart'); }
require(["Authentication/Scripts/SPS.Authentication.Controls","Authentication/Scripts/SPS.Authentication"], function(){  if (window.performance && window.performance.mark) { window.performance.mark('requireEnd'); } window.requiredModulesLoaded=true;  });
</script>

</body>
</html>

So, obviously, your authentication might time out – but Azure DevOps also invalidates your session if you log into another Azure DevOps organization, and if that happens in a background tab or another browser window, you might’ve done it somewhat inadvertently. And even if not, it’s still annoying – you might’ve had a work item open and modified and suddenly you can’t save the changes!

But there’s a solution :)

Solution

Easy – essentially, you’ll just need to refresh your authentication. Something like below:

Time needed: 10 minutes.

How to save unsaved changes when Azure DevOps throws “Unexpected token < in JSON at position 4” -error?

  1. Refresh the page

    If you don’t have any unsaved changes, just refresh the page. That’s the simplest choice :)

  2. Open a background tab to your organization’s home page

    This looks something like this:
    https://dev.azure.com/contosoprojects (where contosoprojects is your organization’s name)

  3. Authenticate

    Even if you should’ve had an active session, you should still be asked to authenticate – which you’ll need to do. Just use whatever account you used before for this organization, it might even show up as “signed in”.

  4. Try saving (or refreshing or whatever it was) again

    After authenticating in a background tab, you can close it, and try redoing whatever it was that didn’t work in the first tab before. Now, the error should be gone!

    To be fair, even though you should be able to save changes, some of the things might still not work. For example, the people picker might still fail:
    This image has an empty alt attribute; its file name is image-6.png


And that’s all for today. Pretty simple, eh? 😂

mm
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments