Bug 51591: NS_MAIN pages break on JSON edge cases.

When the JSON sections array was empty, or when the title of the
NS_MAIN page was not included in the section array, the whole
page would break due to a counting issue.

Bug: 51591
Change-Id: I280ce82b67a8a25f5bfb9075f34c2db4ef542d00