Parse streaming JSON

本秂侑毒 提交于 2019-12-13 02:37:27

问题


I've got a tool I'm working on that parses Neo4j responses and emits objects.

https://github.com/brian-gates/neo4j-stream-deserializer

My questions:

  1. How can I handle errors?
  2. Is there a better way to handle headers than two parsers? Seems like unnecessary overhead.

The possible error responses look like this:

{ message: 'Error explanation, ... other useful info ... }

Full example:

https://gist.github.com/brian-gates/4a16e0aee13d6e549d52

With successful responses looking like this:

{ columns: [], results: [] }

https://github.com/brian-gates/neo4j-stream-deserializer/blob/master/test/mock/neo4j_response.json


回答1:


You might be interested in Oboe.js, a library which I maintain: Oboe.js on Github




回答2:


Try checking header status. If not 200 OK, don't use the streaming parser, just forward the error to the caller.

It gets more tricky with the transactional cypher endpoint (which responds with 200 if there are errors, because each statement can have separate errors), but with the normal cypher endpoint this should work fine.



来源:https://stackoverflow.com/questions/21566865/parse-streaming-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!