Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an "Unexpected token: error when parsing the JSON output. #59

Closed
dweaver33 opened this issue Apr 1, 2022 · 3 comments
Closed

Comments

@dweaver33
Copy link

I'm getting the error SyntaxError: Unexpected token : in JSON at position 2 when running against the following JSON:

[
    {
        "file": "models/linting_test.sql",
        "line": 9,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 10,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 14,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L036: Select targets should be on a new line unless there is only one select target.",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 15,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 16,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 18,
        "start_column": 15,
        "end_column": 15,
        "title": "SQLFluff",
        "message": "L009: Files must end with a single trailing newline.",
        "annotation_level": "failure"
    }
]
@dweaver33
Copy link
Author

Seems related this: sqlfluff/sqlfluff-github-actions#15

So maybe not an issue here?

@ggrossetie
Copy link
Member

Not sure, your JSON seems valid... 🤔
We are using JSON.parse (nothing fancy) and I can confirm that the following is running fine:

const result = JSON.parse(`[
    {
        "file": "models/linting_test.sql",
        "line": 9,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 10,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 14,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L036: Select targets should be on a new line unless there is only one select target.",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 15,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 16,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 18,
        "start_column": 15,
        "end_column": 15,
        "title": "SQLFluff",
        "message": "L009: Files must end with a single trailing newline.",
        "annotation_level": "failure"
    }
]`)

console.log({result})

Might be an encoding issue or an invalid character somewhere (non-breaking space, zero-width space...).
For reference, here's the relevant code:

annotations-action/index.js

Lines 123 to 124 in 20b64ec

const inputContent = await fs.readFile(inputPath, { encoding: 'utf8' })
return JSON.parse(inputContent)

@dweaver33
Copy link
Author

Hi @Mogztter, I actually ended up fixing this by implementing the fix described here: sqlfluff/sqlfluff-github-actions#15 (comment)

Seems like it might be more of a dbt issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants