Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double encoding of json #1482

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public function normalize(Entry $entry) : string|float|int|bool|array|null
Entry\DateEntry::class => $entry->value()?->format($this->dateFormat),
Entry\TimeEntry::class => $entry->value() ? date_interval_to_microseconds($entry->value()) : null,
Entry\EnumEntry::class => $entry->value()?->name,
Entry\JsonEntry::class => $entry->value(),
Entry\ListEntry::class,
Entry\MapEntry::class,
Entry\StructureEntry::class,
Entry\JsonEntry::class,
Entry\XMLElementEntry::class => $entry->toString(),
Entry\XMLEntry::class => $entry->toString(),
default => $entry->value(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function Flow\ETL\Adapter\JSON\from_json;
use function Flow\ETL\Adapter\Json\to_json;
use function Flow\ETL\DSL\{average, df, from_array, overwrite, ref};
use function Flow\ETL\DSL\{average, df, from_array, from_rows, int_entry, json_entry, overwrite, ref, row};
use function Flow\ETL\DSL\{config, flow_context, rows};
use function Flow\Filesystem\DSL\path;

Expand Down Expand Up @@ -113,6 +113,28 @@ public function test_json_loader_overwrite_mode() : void
}
}

public function test_jsonentry_json_file() : void
{
$jsonObject = ['short' => 'short_description', 'long' => 'long_description'];
df()
->read(from_rows(rows(
row(
int_entry('id', 1),
json_entry('nested', $jsonObject),
)
)))
->saveMode(overwrite())
->write(to_json($path = __DIR__ . '/var/test_jsonentry.json'))
->run();

self::assertStringContainsString(
<<<'JSON'
[{"id":1,"nested":{"short":"short_description","long":"long_description"}}]
JSON,
\file_get_contents($path)
);
}

public function test_partitioning_json_file() : void
{
df()
Expand Down