Skip to content

zoncoen/query-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

20ae25e · Jan 25, 2024
Jan 25, 2024
Nov 3, 2022
Jan 25, 2024
Jan 25, 2024
Nov 3, 2022
Nov 3, 2022
Nov 13, 2022
Apr 23, 2023
May 27, 2019
Apr 23, 2023
Jan 25, 2024
Nov 9, 2022
May 27, 2019
Nov 9, 2022
Nov 9, 2022
Nov 7, 2023
Nov 7, 2023
May 27, 2019
May 27, 2019
Jan 25, 2024
Jan 25, 2024
Jan 24, 2024
Nov 3, 2022
Nov 3, 2022
Jan 24, 2024
Nov 9, 2022
May 27, 2019

Repository files navigation

query-go

GoDoc coverage ratio Go Report Card LICENSE

This is a Go package to extract element from a Go value by a query string like $.key[0].key['key']. See usage and example in GoDoc.

Basic Usage

ParseString parses a query string and returns the query which extracts the value.

q, err := query.ParseString(`$.key[0].key['key']`)
v, err := q.Extract(target)

Query Syntax

The query syntax understood by this package when parsing is as follows.

$           the root element
.key        extracts by a key of map or field name of struct ("." can be omitted if the head of query)
['key']     same as the ".key" (if the key contains "\" or "'", these characters must be escaped like "\\", "\'")
[0]         extracts by a index of array or slice