Skip to content

WIP Feature request for object conversion #19

@linw1995

Description

@linw1995

Implements a simple and easy for usage syntax for object conversion.

Functions

Common Conversion

assert parse("${a:b, b:a}") \
    .find({"a": 1, "b": 2}) == [{"b": 1, "a": 2}], "swaps values between a and b" 
assert parse("${username:author_name, age:author_age}") \
    .find({
        "author_name": "Jade",
        "author_age": 18,
        "boo": "boo"
    }) == [{"username": "Jade", "age": 18}], "Rearranges the key-value pairs"

Conversion Can Be Applied To Array

assert parse("$[{a:b}]").find([{"b": 1}, {"c": 1}]) == [{"a": 1}, {"a": None}]
assert parse("$[{a:b}][a != null]").find([{"b": 1}, {"c": 1}]) == [{"a": 1}]

Nested Conversion

assert parse("${author: {name: author_name}}") \
    .find({"author_name": "Jade"}) == [{"author": {"name": "Jade"}}]

Or the key of the key-value pair may be chained path which components are name only, e.g. boo.bar

assert parse("${author.name: author_name}") \
    .find({"author_name": "Jade"}) == [{"author": {"name": "Jade"}}]

The Value Of The Key-Value Pair May Be An Expression

assert parse("${name: author.name}") \
    .find({"author": {"name": "Jade"}}) == [{"name": "Jade"}]

WIP Update key-value pairs

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions