0.70 Extended JSON parse error on --minify: How to debug?

$  hugo -b="https://www.psychedelicsdaily.com/" -v --minify
INFO 2020/05/15 15:10:21 Using config file: 
Building sites … INFO 2020/05/15 15:10:21 syncing static files to /var/www/psychedelicsdaily.com-hugo/public/
ERROR 2020/05/15 15:10:24 JSON parse error: expected comma character or an array or object ending on line 26 and column 6
   26:     }{
            ^
ERROR 2020/05/15 15:10:24 JSON parse error: expected comma character or an array or object ending on line 26 and column 6
   26:     }{
            ^
ERROR 2020/05/15 15:10:24 JSON parse error: expected comma character or an array or object ending on line 26 and column 6
   26:     }{
            ^
ERROR 2020/05/15 15:10:24 JSON parse error: expected comma character or an array or object ending on line 26 and column 6
   26:     }{
            ^
Total in 5051 ms
Error: Error building site: failed to render pages: JSON parse error: expected comma character or an array or object ending on line 19 and column 6
   19:     }{
            ^

When I use --minify when building, I get these errors, but I can’t seem to figure out which files or where this error is. I’ve no idea where this error is. In which file is it?

I’ve tried verbose and I get nothing.

$  ls resources/_gen/assets/css/css/style.css_
style.css_59c079fdb5c26f5cc0ae75aded8b472a.content  style.css_59c079fdb5c26f5cc0ae75aded8b472a.json     style.css_674d3a8c056e8697f10ad004211806b8.content  style.css_674d3a8c056e8697f10ad004211806b8.json

That’s all I have as .json in my project. However, --ignoreCache does not help.

It gives all those errors on build, but the site is still built fine and minfied as well seeminly. What is happening? I’m quite befuddled here.

Post the original json file. The errors are quite clear, “we” expect a comma or an array on line 26 and column 6. It’s about a JSON file, so probably style.css_674d3a8c056e8697f10ad004211806b8.json or whatever creates it.

Post a link to a repo where we can re-create the issue.

I don’t have any JSON files in my project which would be minified. As you can see, it’s style.css that’s being turned into .json somehow. style.css is produced by hugo resources (from many different css files). resource is something hugo generates, which I was told using --ignoreCache would ignore.

	{{ $base := resources.Get "base.css" }}
	{{ $custom := resources.Get "custom.css" }}
	{{/* $fa := resources.Get "font-awesome.css" */}}
	{{ if hugo.IsProduction }}
		{{ $css := slice $base $custom | resources.Concat "css/style.css" | resources.Minify | resources.PostCSS | resources.PostProcess }}
		<link href="{{ $css.Permalink  }}" rel="stylesheet"/>
	{{ else }}
		<link href="{{ $base.Permalink }}" rel="stylesheet"/>
		<link href="{{ $custom.Permalink }}" rel="stylesheet"/>
		<!--<link href="{{/* $fa.Permalink */}}" rel="stylesheet"/>-->
	{{ end }}

I don’t understand quite clearly what’s happening with the JSON error, and exactly which file is hugo complaining about? I’ve looked at all the JSON I have in my project, json+ld data, any other data, and it’s all valid json.

The only json data file I have is /data/read/top.json which I got from Google Analytics API to prepare for a Most read articles section of the month for my site. I verified it at https://jsonformatter.curiousconcept.com/ as valid json.

[
  {
    "url": "/psychedelics/psilocybin/do-shrooms-show-up-on-drug-test/",
    "title": "Do Shrooms Show Up On Drug Test?",
    "views": 18299
  },
  {
    "url": "/psychedelics/psilocybin/shroom-dose-calculator/",
    "title": "Shroom Dose Calculator",
    "views": 9639
  },
  {
    "url": "/psychedelics/lsd/does-lsd-show-up-on-drug-test-guide-to-lsd-drug-testing/",
    "title": "Does LSD Show Up On Drug Test? Guide to LSD Drug Testing!",
    "views": 7729
  },
  {
    "url": "/psychedelics/microdosing/how-to-prepare-a-psilocybin-mushroom-microdose/",
    "title": "How to Prepare a Psilocybin Mushroom Microdose",
    "views": 6941
  },
  {
    "url": "/psychedelics/microdosing/microdose-mushrooms-in-7-easy-steps/",
    "title": "Microdose Mushrooms in 7 Easy Steps",
    "views": 3285
  },
  {
    "url": "/psychedelics/lsd/9-facts-about-lsd-everyone-should-know/",
    "title": "9 Facts About LSD Everyone Should Know",
    "views": 2638
  },
  {
    "url": "/psychedelics/psilocybin/three-things-to-know-about-psilocybin-mushrooms/",
    "title": "Three Things To Know About Psilocybin Mushrooms",
    "views": 2366
  },
  {
    "url": "/psychedelics/microdosing/best-microdosing-schedule-by-dr.-james-fadiman/",
    "title": "Best Microdosing Schedule By Dr. James Fadiman",
    "views": 2193
  },
  {
    "url": "/psychedelics/microdosing/microdose-acid-in-7-easy-steps/",
    "title": "Microdose Acid in 7 Easy Steps",
    "views": 1808
  },
  {
    "url": "/psychedelics/psilocybin/do-shrooms-show-up-on-drug-test/",
    "title": "Do Shrooms Show Up On Drug Test?",
    "views": 1179
  },
  {
    "url": "/psychedelics/microdosing/how-to-prepare-a-psilocybin-mushroom-microdose/",
    "title": "How to Prepare a Psilocybin Mushroom Microdose",
    "views": 954
  },
  {
    "url": "/psychedelics/microdosing/microdosing-benefits-of-lsd-and-psilocybin-mushrooms/",
    "title": "Microdosing Benefits of LSD and Psilocybin Mushrooms",
    "views": 951
  },
  {
    "url": "/psychedelics/microdosing/everything-you-need-to-know-about-microdosing-4-aco-dmt/",
    "title": "Everything You Need To Know About Microdosing 4-AcO-DMT",
    "views": 903
  },
  {
    "url": "/psychedelics/lsd/does-lsd-show-up-on-drug-test-guide-to-lsd-drug-testing/",
    "title": "Does LSD Show Up On Drug Test? Guide to LSD Drug Testing!",
    "views": 659
  },
  {
    "url": "/psychedelics/microdosing/how-to-microdose-acid-and-magic-mushrooms/",
    "title": "How to Microdose Acid and Magic Mushrooms?",
    "views": 628
  },
  {
    "url": "/psychedelics/microdosing/microdose-4-aco-dmt-in-7-easy-steps/",
    "title": "Microdose 4-AcO-DMT in 7 Easy Steps!",
    "views": 618
  },
  {
    "url": "/psychedelics/psilocybin/three-things-to-know-about-psilocybin-mushrooms/",
    "title": "Three Things To Know About Psilocybin Mushrooms",
    "views": 529
  },
  {
    "url": "/psychedelics/salvia/5-important-tips-for-new-salvia-users/",
    "title": "5 Important Tips For New Salvia Users - Best Resources For The Responsible Use Of",
    "views": 134
  }
]

Other than that, there is package.json and manifest.json which are also valid. package.json is not used by hugo, but by node. And manifest.json is not a resource to be minified or processed, just a file in /public/

It throws these errors, however, the site is still generated and minified.

I mean if during minification --minify in Hugo, the css resource is converted to JSON .json file, then even that is peculiar because https://jigsaw.w3.org/css-validator/validator?uri=https%3A%2F%2Fwww.psychedelicsdaily.com%2F reports my css as valid. No errors.

I made a bit of progress. Since I am generating content from various online sources via some bit of scraping, I figured the problem would have to be in the /drugs section.

I deleted all /drugs/*.md files and site builds with --minify, no errors.

Then I regenerate the .md files, and build again, errors. So I remove each file one by one to check.

These are the content files I ma generating.

$  hugo --minify
Total in 1831 ms
Error: Error building site: failed to render pages: JSON parse error: expected comma character or an array or object ending on line 26 and column 6
   26:     }{
            ^
+++
author = "hash"
authors = "hash-borgir"
banner = "img/molecules/generic_molecule_placeholder.svg"
categories = ["Drug Facts"]
date = "2020-05-15T16:38:48-06:00"
description = "A psychedelic RC of the NBOMe class of drugs that is expected to cause hallucinations. Limited human use has been recorded on this drug and caution should be used with dosing."
featured=false
images = ["/img/molecules/generic_molecule_placeholder.svg"]
reviewCount = ""
tags = ["Drug Facts", "Molecules"]
title = "25T-4-NBOMe "

aliases = [
    "/25T-4-NBOMe",
]
+++

# 25T-4-NBOMe

{{< imgcap src="/img/molecules/generic_molecule_placeholder.svg" title="25T-4-NBOMe" align="" width="300px" >}}

Common Names: 25t4-nbome

{{<rc>}}

{{<psy>}}

{{<tentative>}}



# Description

25T-4-NBOMe A psychedelic RC of the NBOMe class of drugs that is expected to cause hallucinations. Limited human use has been recorded on this drug and caution should be used with dosing.

# Summary

<p></p>

# History

<p></p>

# Chemistry



# Dosing Guide

<table></table><table></table><table></table>

# Duration

<table></table>

# Interactions and Synergies

{{<nodata>}}

# General Information


<table>
<tbody>
<tr class="odd">
<td>Experiences</td>
<td></td>
</tr>
<tr class="even">
<td>Oral</td>
<td></td>
</tr>
<tr class="odd">
<td>Vaporization</td>
<td></td>
</tr>
<tr class="even">
<td>Come up</td>
<td></td>
</tr>
<tr class="odd">
<td>Dosage</td>
<td></td>
</tr>
<tr class="even">
<td>Effects</td>
<td></td>
</tr>
<tr class="odd">
<td>After Effects</td>
<td></td>
</tr>
<tr class="even">
<td>Avoid</td>
<td></td>
</tr>
<tr class="odd">
<td>Warning</td>
<td></td>
</tr>
<tr class="even">
<td>Risks</td>
<td></td>
</tr>
<tr class="odd">
<td>Test Kits</td>
<td></td>
</tr>
<tr class="even">
<td>Marguis Test Result</td>
<td></td>
</tr>
<tr class="odd">
<td>Tolerance</td>
<td></td>
</tr>
<tr class="even">
<td>Detection</td>
<td></td>
</tr>
<tr class="odd">
<td>Half-life</td>
<td></td>
</tr>
<tr class="even">
<td>Advice</td>
<td></td>
</tr>
<tr class="odd">
<td>Note</td>
<td></td>
</tr>
<tr class="even">
<td>Note 2:</td>
<td></td>
</tr>
<tr class="odd">
<td>Note 3:</td>
<td></td>
</tr>
</tbody>
</table>




# Effects


## Pharmacological Effects




## Subjective Effects




## Physical Effects





## Psychological Effects




## Visual Effects




## Auditory Effects




## Sensory Effects



## Transpersonal Effects




# Legal Status





# References



I don’t see any JSON anywhere! I’m so confused. In any of the generated files.

In fact, the generated .md files by my script contain absolutely no {} curly.

Here is another generated file from my script, this one has more content, but no curlies.

File too large to post here:

I am absolutely confused. I just can’t find anything about that error in my files. But the problem is definitely somewhere in my generated markdown files.

Again, please post a link to a repo where we can re-create the issue.

I’ve made it public.

Specifically:

These files are generated via a PHP script.

Are you running Hugo as a snap?

I am not. I am using the .deb package of latest Hugo extended on Ubuntu 18.04 LTS

OK, here’s what I did:

git clone https://gitlab.com/hashborgir/psychedelicsdaily.com-hugo.git
cd psychedelicsdaily.com-hugo
npm ci
hugo

And here’s what I got:

Building sites … You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js.

                   |  EN   
-------------------+-------
  Pages            |  297  
  Paginator pages  |    5  
  Non-page files   |   28  
  Static files     | 1703  
  Processed images |    0  
  Aliases          |  265  
  Sitemaps         |    1  
  Cleaned          |    0  

Total in 4076 ms

–minify

Do you get the errors?

This is an issue only when building with --minify

OK, I’ve reproduced the problem. I’ll have another look over the weekend.

Thank you.

I am going to rework my .md file generation script as well. I’ve gone through every line of code and I can’t find anything that would indicate this error.

What would help is if Hugo could give us the name of the files where these errors occur.

First, every HTML page on your site contains JSON data. At the bottom of each page there are three <script type="application/ld+json"> elements. These contain JSON data. These three elements are added to the page by themes/hugo-universal-theme/layouts/partials/seo/schema.html.

Second, two of the three <script type="application/ld+json"> elements that you create on each page are fine, but the BreadCrumbList is broken – it generates invalid syntax, which is why minification is failing. Here’s the BreadCrumbList generated for http://localhost:1313/drugs/. Note that you’re missing two commas.

{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    },{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/drugs\/\/\/localhost:1313\/drugs\/",
          "name": "drugs"
        }
    }{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    },{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/drugs\/\/\/localhost:1313\/drugs\/\/\/\/localhost:1313\/drugs\/\/\/localhost:1313\/drugs\/",
          "name": "drugs"
        }
    }{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    },{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/drugs\/\/\/localhost:1313\/drugs\/\/\/\/localhost:1313\/drugs\/\/\/localhost:1313\/drugs\/\/\/\/localhost:1313\/drugs\/\/\/localhost:1313\/drugs\/",
          "name": "drugs"
        }
    }]
}

Third, I have abandoned all hope of understanding your breadcrumb code. You are updating $.Scratch "path" in both themes/hugo-universal-theme/layouts/partials/breadcrumbs.html and themes/hugo-universal-theme/layouts/partials/seo/schema.html.

Fourth, until you are able to fix the underlying problem, you can disable JSON minification in config.toml:

[minify]
  disableJSON = true

Finally, you might want to check the spelling of node_modules in your .gitignore file. :slight_smile:

3 Likes

Thank you very much.

This is very peculiar.

I always run with hugo serve --ignoreCache --disableFastRender

I get the following code generated when I dev:

{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    },{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/1b-lsd\/\/\/localhost:1313\/1b-lsd\/",
          "name": "1b-lsd"
        }
    }]
}


When I use hugo serve I get the same result as you.

There is definitely a problem in that code. I’m surprised I didn’t see it before.

I also got the code from here: https://gohugohq.com/partials/breadcrumb-partial-with-structured-data-in-hugo/

When I use hugo serve, I get the following output:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
	
	
	{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    }

    
	,
	{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/1b-lsd\/",
          "name": "1b-lsd"
        }
    }

    
	
	{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    }

    
	,
	{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/1b-lsd\/\/\/\/localhost:1313\/1b-lsd\/",
          "name": "1b-lsd"
        }
    }

    ]
}
</script>

Then while hugo is runing in server mode, I save the schema.html file in my editor.

Then refresh the source tab in browser and I get the following output:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
	
	
	{
        "@type": "ListItem",
        "position":  1 ,
        "item": {
          "@id": "\/\/localhost:1313\/",
          "name": "home"
        }
    }

    
	,
	{
        "@type": "ListItem",
        "position":  2 ,
        "item": {
          "@id": "\/\/localhost:1313\/1b-lsd\/",
          "name": "1b-lsd"
        }
    }

    ]
}
</script>

When I save the file while hugo is running, and generates it a second time, I get correct code generated.

If I shut down hugo serve process, restart it with hugo serve, then the wrong code is generated, with the comma errrors in json.

If I then save file again, without editing or doing anything, I get correct output.

What is happening?

In fact, the same code is used here as well:

I removed my breadcrumb code from breadcrumb.html and kept only the code in this file in my schema.html and I still get errors.

For some odd reason, that’s just not working for me. I can remove the breadcrumb ld+json code for now.

I’ll make another thread about how to properly get ld+json schema breadcrumbs as that is a separate issue now.

Thank you so much! :slight_smile:

Thank you.

EDIT: repository is no longer public.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.