Sample Scripts Unexpected End of JSON

Hi there,

I had copied a sample script from the K6 documentation to use as a sample when trying out the tool. It had been functional when I had first done this, but re-visiting the script, I am now seeing an “unexpected end of JSON input” error.

Nothing has changed in the interim and the error isn’t very helpful to track down the issue.
The sample used was: Single request

I’ve also tried writing an extremely simple script, but it results in the same error.

export default function() {
	console.log('test function');
};

The scripts are being run with k6 run <scriptname>.js using the terminal, from the same location as the file itself.

There are other scripts that I have written which are running fine (using gRPC), so it doesn’t seem like an issue with the installation of k6.

Is there some way to get a more descriptive error message?

Hi @jocochrane, welcome to the community forum :tada:

The only thing that I could think of is that you have corrupted your config and from a quick experiment it will lead to the same error if I remove the last } from ~/.config/loadimpact/k6/config.json.

Can you confirm that if you move the file (please don’t just delete it) and try again it works?

Have you edited it manually and if not can you provide it (maybe in a DM) in hopes that we can figure out what went wrong?

Thanks in advance and hope this helps you

Hi @mstoykov,

Thanks for the tip! Looks like that was the issue. The file was modified as part of a cloud login resolution attempt and we didn’t realize it would affect HTTP scripts.

For anyone else who runs into this issue, the config file on mac is located at …/Library/Application Support/loadimpact/k6/config.json. I moved this file out of the folder and used the login command provided by the cloud CLI dashboard to regenerate the file.

1 Like

Hi @jocochrane glad you fixed it.

Can you expand on how exactly it got corrupted and if I can get a copy :pray: (you can replace the token inside with “TOKEN” or something like hat as well as all other information that you think is sensitive.

I just can’t understand what made it corrupt the config, and it will be nice if we can fix it :slight_smile:

It was probably just user error. We were doing a trial with K6 Cloud and could not login via the k6 login cloud command. One of the suggestions for resolving the issue was to remove any other configuration in the file generated by the login which was not the token.