# How to parse Result object

**URL:** <https://community.neo4j.com/t/how-to-parse-result-object/10390>\
**Category:** Procedures & APOC\
**Tags:** java-api\
**Created:** [September 25, 2019, 1:44am UTC](https://community.neo4j.com/t/how-to-parse-result-object/10390 "2019-09-25T01:44:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![usuallycwdillon](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/usuallycwdillon/32/154_2.png) [@usuallycwdillon](https://community.neo4j.com/u/usuallycwdillon)\
**Post date:** [September 25, 2019, 1:44am UTC](https://community.neo4j.com/t/how-to-parse-result-object/10390/1 "2019-09-25T01:44:02Z")

</div>

I'm writing some custom complicated procedures that make some queries that return a single result, but I haven't figured out how to parse my query result from the Result object returned by the query.

For example, I have a `Result result = db.execute(query, params)`. I can see from my `log.info(result.resultAsString())` that the query returns the correct result.

```auto
| pf.value |
+----------+
| 29480 |
+----------+
1 row

```

However, `Long pop = (Long) result.columnAs("pf.value").next();` returns an error `java.util.NoSuchElementException: next on empty iterator`

How do I get my value out of the Result object?

---

<div class="post-metadata">

**Author:** ![usuallycwdillon](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/usuallycwdillon/32/154_2.png) [@usuallycwdillon](https://community.neo4j.com/u/usuallycwdillon)\
**Post date:** [September 25, 2019, 1:54am UTC](https://community.neo4j.com/t/how-to-parse-result-object/10390/2 "2019-09-25T01:54:40Z")

</div>

Gah! Of course, the "Suggested Topics" after I posted lead me to a post that gave me the example I needed.

The quick answer is:

```auto
Map<String, Object> map = db.execute(query, params).next();
Long pop = (Long) map.get("pf.value");

```

But, I'm still curious how to use the `result.columnAs()` method. I'm obviously reading the API docs wrong.

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [September 25, 2019, 1:54am UTC](https://community.neo4j.com/t/how-to-parse-result-object/10390/3 "2019-09-25T01:54:43Z")

</div>

`result.resultAsString()` consumes all results, so by logging this you can no longer iterate through the result set. From the Result.java documentation:

> In addition to the iteration methods on this interface, close(), and the column projection method, there are two methods for getting a string representation of the result that also consumes the entire result if invoked. resultAsString() returns a single string representation of all (remaining) rows in the result, and writeAsStringTo(PrintWriter) does the same, but streams the result to the provided PrintWriter instead, without allocating large string objects.
> 
> The methods that do not consume any rows from the result, or in other ways alter the state of the result are safe to invoke at any time, even after the result has been closed or fully exhausted. These methods are:
> 
> - columns()
> - getQueryStatistics()
> - getQueryExecutionType()
> - getExecutionPlanDescription()
