Add support for getting json by array index

* Also support json negative array index
This commit is contained in:
steve-chavez
2018-06-19 11:17:59 -05:00
committed by Steve Chávez
parent 2513c00039
commit 30dfadec7b
11 changed files with 172 additions and 21 deletions
+10 -5
View File
@@ -80,11 +80,16 @@ pFieldName = do
dash :: Parser Char
dash = isDash *> pure '-'
pJsonPathStep :: Parser Text
pJsonPathStep = toS <$> try (string "->" *> pFieldName)
pJsonPath :: Parser [Text]
pJsonPath = (<>) <$> many pJsonPathStep <*> ( (:[]) <$> (string "->>" *> pFieldName) )
pJsonPath :: Parser JsonPath
pJsonPath = (<>) <$> many pJsonPathOp <*> ( (:[]) <$> (string "->>" *> (try pJIdx <|> pJKey)) )
where
pJsonPathOp :: Parser JsonPathOp
pJsonPathOp = try (string "->" *> pJIdx) <|> try (string "->" *> pJKey)
pJKey = JKey . toS <$> pFieldName
pJIdx = JIdx . toS <$> ((:) <$> option '+' (char '-') <*> many1 digit) <* pEnd
pEnd = try (void $ lookAhead (string "->")) <|>
try (void $ lookAhead (string "::")) <|>
try eof
pField :: Parser Field
pField = lexeme $ (,) <$> pFieldName <*> option [] pJsonPath