Zero path length

Dear Community,

I have the following Cypher query, where I utilize apoc.dijkstra (However it is the case for other path finding algorithms):

CALL apoc.load.json("file:///D:/...../input.json") YIELD value UNWIND value.origin AS orig 
MATCH(origin:concept{name:orig.label}) WITH value, collect(origin) as origins 
UNWIND AS tar MATCH(target:concept{name:tar.label}) 
UNWIND origins AS origin 
WITH origin, target 
CALL apoc.algo.dijkstra(origin, target, 'link', 'Weight') 
yield path as path, weight as weight 
RETURN path, weight ORDER BY weight DESC

I insert the following JSON to Neo4j:

 {"origin":[{"label":"P1","tag":[],"type":"string","xpath":[]}, {"label":"A","tag": 
 [],"type":"string","xpath":["P1"]}], "target":[{"label":"P2","tag":[],"type":"string","xpath":[]}, 

or (origin: P1, A , target: P2, A) and thus we have the same node both in origin, as well as target. I've got the following output:

[{ "name": "P1",  "type": "string"},{"Weight": 1},{"name": "A", "type": "string"},
{"name": "A", "type": "string"}, {"Weight": 1},{"name": "P2", "type": "string"}]
[{"name": "A","type": "string"},{"Weight": 1},{"name": "P2","type": "string"}]
[{"name": "P1","type": "string"},{"Weight": 1},{"name": "A","type": "string"}]
[{"name": "A", "type": "string"}, null]

My problem is, as you can see in the last line I got:

  [{"name": "A", "type": "string"}, null]

The null value, is it possible to somehow modify the output in order to get something similar to previous lines, for instance:

 [{"name": "A", "type": "string"}, {"Weight": 0},{"name": "A","type": "string"}]

instead of just:

  [{"name": "A", "type": "string"}, null]

As it can cause several difficulties and inconveniences for further parsing of the output, later while combining all suggestions for each origin and loop over the records it is desirable to have similar format for all path suggestions like (node -- Weight -- node, node -- Weight -- node). And I still need to consider pointing on the node itself as one of possible suggestions. I would appreciate, if you could help me. Thank you in advance!

You could construct a path with some of the apoc.path functions.

Or use coalesce on the null value to turn it into a zero-weight plus the head(nodes(path))