Skip to content

copy_field + double replace_all + array of objects and asteriks copies too often #724

@TobiasNx

Description

@TobiasNx

Input:

{
    "Hello": "World/download"
}

Flux:

inputFile
| open-file
| as-records
| decode-json
| fix(transformationFile)
| encode-yaml
| print
;

Fix:

add_array("encoding[]")
if exists("Hello")
  copy_field("Hello","encoding[].$append.contentUrl")
  add_field("encoding[].$last.type", "MediaObject")
  if any_contain("Hello","o")
    add_field("encoding[].$append.type", "MediaObject")
    copy_field("Hello", "encoding[].$last.embedUrl")
    copy_field("Hello", "image")
  end
end

replace_all("encoding[].*.embedUrl","download","preview")
replace_all("image","download","thumbnail")

Output:

---
Hello: "World/download"
encoding:
- contentUrl: "World/download"
  type: "MediaObject"
  embedUrl: "World/preview"
- type: "MediaObject"
  embedUrl: "World/download"
image: "World/thumbnail"

Expected:

---
Hello: "World/download"
encoding:
- contentUrl: "World/download"
  type: "MediaObject"
- type: "MediaObject"
  embedUrl: "World/download"
image: "World/download"

If replace_all("image","download","thumbnail") is outcommented the mapping is working correctly

Example in Playground

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions