Query

Parsing

Serde.SerdeQuery.parse_queryFunction
parse_query(x::Union{AbstractString, Vector{UInt8}}; dict_type = Dict{String,Any}, delimiter = "&") -> Dict

Parse a URL-encoded query string into a Dict without mapping to a target type.

Keys and values are percent-decoded. Repeated keys (e.g. a=1&a=2) produce a Vector of values.

Arguments

  • x: query string as String or Vector{UInt8} (leading ? should be stripped).

Keyword arguments

  • dict_type::Type{<:AbstractDict}: concrete dict type (default Dict{String,Any}).
  • delimiter::AbstractString = "&": pair separator.

Returns

A dict mapping decoded keys to decoded values (or vectors of values).

Throws

  • ParseError: if the query string contains invalid percent-encoding or semicolons.

Examples

julia> parse_query("name=Alice&age=30")
Dict{String, Any}("name" => "Alice", "age" => "30")

julia> parse_query("color=red&color=blue")
Dict{String, Any}("color" => ["red", "blue"])

See also: from_query, try_from_query.

source

Deserialization

Serde.SerdeQuery.from_queryFunction
from_query(::Type{T}, x; kw...) -> T
from_query(strategy, ::Type{T}, x; kw...) -> T
from_query(f::Function, x; kw...) -> Any

Parse a URL query string and deserialize it into type T.

All values in a query string are strings; the deserialization engine handles type coercion for each field. Vector/Set fields are populated from repeated keys or bracket notation.

Pass a strategy object (e.g. CamelCase()) to apply global field-renaming.

Arguments

  • ::Type{T}: target type to construct.
  • x: query string as String or Vector{UInt8}.
  • strategy: optional serialization strategy.

Returns

A value of type T.

Throws

Examples

julia> struct Filter; name::String; limit::Int; end

julia> from_query(Filter, "name=Alice&limit=10")
Filter("Alice", 10)

See also: try_from_query, to_query, parse_query.

source

Serialization

Serde.SerdeQuery.to_queryFunction
to_query(data; delimiter = "&", sort_keys = false, escape = true) -> String
to_query(strategy, data; delimiter = "&", sort_keys = false, escape = true) -> String

Serialize data into a URL-encoded query string.

Struct fields and dict keys become query parameter names; values are converted to strings. Vector and Set values are serialized in bracket notation ([v1,v2]). Null values (nothing, missing) and skipped fields are omitted.

Pass a strategy object (e.g. CamelCase()) to apply global field-renaming.

All serialization traits (Serde.ser_name, Serde.ser_value, Serde.ser_skip) are applied.

Arguments

  • data: value to serialize (struct or dict).
  • strategy: optional serialization strategy.

Keyword arguments

  • delimiter::AbstractString = "&": separator between key=value pairs.
  • sort_keys::Bool = false: sort parameter names lexicographically before output.
  • escape::Bool = true: percent-encode characters outside the unreserved set.

Returns

A query string String (without a leading ?).

Examples

julia> struct Search; query::String; limit::Int; end

julia> to_query(Search("hello world", 10))
"query=hello%20world&limit=10"

julia> to_query(Search("hello world", 10); escape=false)
"query=hello world&limit=10"

julia> to_query(Search("hello", 10); sort_keys=true)
"limit=10&query=hello"

See also: from_query.

source