Skip to content

Commit

Permalink
Fix double encoding of json (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmortlock authored Feb 17, 2025
1 parent 330ddb8 commit 2b3e452
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit 2b3e452

Please sign in to comment.