question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not parse JSON in file Expected BEGIN_ARRAY but was BEGIN_OBJECT

See original GitHub issue

hello, i have an issue with json file, after testing with failure, the json file that has failure is :

[
  {
    "line": 43,
    "elements": [
      {
        "start_timestamp": "2020-04-24T07:28:01.436Z",
        "line": 44,
        "name": "Demonstrating how add in calculator works",
        "description": "",
        "id": "calculator-feature;demonstrating-how-add-in-calculator-works",
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "result": {
              "duration": 6835000000,
              "status": "passed"
            },
            "line": 45,
            "name": "I have a configured calculator",
            "match": {
              "location": "stepdefs.DemoClassTest.i_have_a_configured_calculator()"
            },
            "keyword": "Given "
          },
          {
            "result": {
              "duration": 2828000000,
              "status": "passed"
            },
            "line": 46,
            "name": "I calculate",
            "match": {
              "location": "stepdefs.DemoClassTest.i_calculate()"
            },
            "keyword": "When "
          },
          {
            "result": {
              "error_message": "java.lang.AssertionError: expected [4] but found [3]\r\n\tat org.testng.Assert.fail(Assert.java:97)\r\n\tat org.testng.Assert.assertEqualsImpl(Assert.java:136)\r\n\tat org.testng.Assert.assertEquals(Assert.java:118)\r\n\tat org.testng.Assert.assertEquals(Assert.java:575)\r\n\tat org.testng.Assert.assertEquals(Assert.java:585)\r\n\tat stepdefs.DemoClassTest.i_the_result_should_be(DemoClassTest.java:73)\r\n\tat ✽.I the result(file:///D:/Work/eclipse-workspace/cucumber-jvm-template4/src/test/resources/demo.feature:47)\r\n",
              "duration": 1048000000,
              "status": "failed"
            },
            "line": 47,
            "name": "I the result",
            "match": {
              "location": "stepdefs.DemoClassTest.i_the_result_should_be()"
            },
            "keyword": "Then "
          }
        ]
      }
    ],
    "name": "Calculator Feature",
    "description": "",
    "id": "calculator-feature",
    "keyword": "Feature",
    "uri": "file:src/test/resources/demo.feature",
    "tags": []
  },
  {
    "description": "Test run failed",
    "elements": {
      "description": "There were errors during the execution",
      "result": {
        "error_message": "java.lang.AssertionError: expected [4] but found [3]",
        "status": "failed"
      }
    }
  }
]

and the success test is:

 [
  {
    "line": 43,
    "elements": [
      {
        "start_timestamp": "2020-04-24T07:26:03.391Z",
        "line": 44,
        "name": "Demonstrating how add in calculator works",
        "description": "",
        "id": "calculator-feature;demonstrating-how-add-in-calculator-works",
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "result": {
              "duration": 7517000000,
              "status": "passed"
            },
            "line": 45,
            "name": "I have a configured calculator",
            "match": {
              "location": "stepdefs.DemoClassTest.i_have_a_configured_calculator()"
            },
            "keyword": "Given "
          },
          {
            "result": {
              "duration": 2850000000,
              "status": "passed"
            },
            "line": 46,
            "name": "I calculate",
            "match": {
              "location": "stepdefs.DemoClassTest.i_calculate()"
            },
            "keyword": "When "
          },
          {
            "result": {
              "duration": 1055000000,
              "status": "passed"
            },
            "line": 47,
            "name": "I the result",
            "match": {
              "location": "stepdefs.DemoClassTest.i_the_result_should_be()"
            },
            "keyword": "Then "
          }
        ]
      }
    ],
    "name": "Calculator Feature",
    "description": "",
    "id": "calculator-feature",
    "keyword": "Feature",
    "uri": "file:src/test/resources/demo.feature",
    "tags": []
  }
]

if i remove the end of line int json file that has failure test, and run mvn cluecumber-report:reporting, the html report suddenly working but if i don’t remove the line, in command line after i running mvn test the report html generated but the data not showing the troublesome line in failed test :

{
    "description": "Test run failed",
    "elements": {
      "description": "There were errors during the execution",
      "result": {
        "error_message": "java.lang.AssertionError: expected [4] but found [3]",
        "status": "failed"
      }
    }

And there is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.cucumbertest</groupId>
	<artifactId>cucumber-jvm-template4</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>com.trivago.rta</groupId>
				<artifactId>cluecumber-report-plugin</artifactId>
				<version>2.3.4</version>
				<executions>
					<execution>
						<id>report</id>
						<phase>test</phase>
						<goals>
							<goal>reporting</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<sourceJsonReportDirectory>${project.build.directory}/cucumber-reports</sourceJsonReportDirectory>
					<generatedHtmlReportDirectory>${project.build.directory}/generated-report</generatedHtmlReportDirectory>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>3.0.0-M4</version>
				<configuration>
					<testFailureIgnore>true</testFailureIgnore>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-java8</artifactId>
			<version>6.0.0-RC1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-java</artifactId>
			<version>6.0.0-RC1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-jvm</artifactId>
			<version>6.0.0-RC1</version>
			<type>pom</type>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-core</artifactId>
			<version>6.0.0-RC1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>gherkin</artifactId>
			<version>13.0.0</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-testng</artifactId>
			<version>6.0.0-RC1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-picocontainer</artifactId>
			<version>6.0.0-RC1</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
		<dependency>
			<groupId>net.masterthought</groupId>
			<artifactId>cucumber-reporting</artifactId>
			<version>5.2.0</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
		<dependency>
			<groupId>io.appium</groupId>
			<artifactId>java-client</artifactId>
			<version>7.3.0</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>3.141.59</version>
		</dependency>
	</dependencies>
</project>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
fedyfahronguntaracommented, Apr 24, 2020

thanks for your advice, it’s all good now

best of luck

0reactions
mpkorstanjecommented, Apr 24, 2020

I doubt you have downgraded properly. If you are using IDEA/Eclipse make sure that you reimport your project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 ...
I'm getting below error. Failed to parse JSON due to: com.google.gson.
Read more >
How to fix "expected begin_array but was begin_object" in ...
The error "expected begin_array but was begin_object" occurs if you are trying to parse the above response using Call<List<Example>> call= ...
Read more >
Could not parse JSON in file Expected BEGIN_ARRAY but ...
hello, i have an issue with json file, after testing with failure, the json file that has failure is : [ { "line":...
Read more >
How to resolve "Expected BEGIN_OBJECT but was ...
How to resolve Expected BEGIN_OBJECT but was BEGIN_ARRAY using Gson in Java? - While deserializing, a Gson can expect a JSON object but...
Read more >
Expected BEGIN OBJECT but was BEGIN ARRAY at line 1 ...
Here i am using retrofit post request:- RequestBody name = RequestBody.create(MediaType.parse("text/ ... = response.body().getData().
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found