ComposantsComponents › Fichier › SortieFile › Output
Écrit les lignes d'un flux dans un fichier JSON : un objet par ligne, avec une clé par colonne, rangés dans un tableau. Le tableau est placé sous une clé nommée, {"data":[…]}, ou forme tout le fichier, […]. Les objets sont plats, sans niveau imbriqué, et tout le fichier tient sur une seule ligne.
Writes the rows of a flow to a JSON file: one object per row, with one key per column, stored in an array. The array is placed under a named key, {"data":[…]}, or makes up the whole file, […]. Objects are flat, with no nested level, and the whole file fits on a single line.
EntréeInput
Main un flux, obligatoireone flow, required
SortieOutput
Main un flux, facultatif : les lignes repartent telles quellesone flow, optional: the rows go on unchanged
Déclencheurs en sortieOutput triggers
On Component Ok On Component Error Run if
Chaque ligne lue devient un objet {"colonne":valeur,…} du tableau.
Each row read becomes a {"column":value,…} object of the array.
Les lignes sont écrites dans le fichier, puis passées sans changement au composant suivant. The rows are written to the file, then passed unchanged to the next component.
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de paramètre d'encodage : le fichier est écrit dans l'encodage par défaut de Java, UTF-8 dans nos essais (Java 21). Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no encoding setting: the file is written in the Java default encoding, UTF-8 in our tests (Java 21).
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Nom de fichierFile NameFILENAME | chemin par défaut + /out.jsondefault path + /out.json |
ToujoursAlways | Le fichier écrit, en expression Java. Il est remplacé à chaque exécution : le composant n'a pas d'option pour écrire à la suite. The written file, as a Java expression. It is replaced at each run: the component has no option to append. |
| Générer un tableau JSONGenerate an array jsonGENERATE_JSON_ARRAY | NonNo | ToujoursAlways |
Décochée, le fichier est un objet dont la seule clé, le bloc de données, contient le tableau : {"data":[…]}. Cochée, le fichier est le tableau seul : […].
Unchecked, the file is an object whose only key, the data block, holds the array: {"data":[…]}. Checked, the file is the array alone: […].
|
| Nom du bloc de donnéesName of data blockDATABLOCKNAME | "data" |
Tableau décochéArray unchecked | La clé qui porte le tableau, en expression Java. D'après le modèle, elle est écrite telle quelle, sans échappement : évitez les guillemets et les barres obliques inverses. The key that holds the array, as a Java expression. Per the template, it is written as it is, without escaping: avoid quotes and backslashes. |
| SchémaSchemaSCHEMA | — | ToujoursAlways | Les colonnes écrites ; leurs noms sont les clés. Elles viennent du lien entrant. Le type de chaque colonne décide de l'écriture de sa valeur (voir les exemples). The written columns; their names are the keys. They come from the incoming link. The type of each column decides how its value is written (see the examples). |
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Créer le répertoire s'il n'existe pasCreate directory if it does not existCREATE | OuiYes | ToujoursAlways | Crée le dossier du fichier, avec ses parents. Décochée, un dossier absent arrête le composant (voir les erreurs). Creates the folder of the file, with its parents. Unchecked, a missing folder stops the component (see the errors). |
NB_LINE (Integer, disponible après l'exécution du composant) : nombre de lignes écrites, donc d'objets du tableau. NB_LINE (Integer, available after the component has run): number of rows written, so of objects in the array.
((Integer) globalMap.get("tFileOutputJSON_1_NB_LINE"))
Un tFixedFlowInput envoie les lignes ci-dessous au tFileOutputJSON_1. Les chemins sont écrits à partir de la variable de contexte folder. Un tJava relié par On Subjob Ok affiche ensuite le fichier écrit ; les sorties sont celles de la console, copiées depuis une exécution du job.
A tFixedFlowInput sends the rows below to tFileOutputJSON_1. Paths are written from the folder context variable. A tJava connected with On Subjob Ok then prints the written file; the outputs are the console ones, copied from a run of the job.
| idInteger | nameString | cityString |
|---|---|---|
| 1 | Ada | London |
| 2 | Grace | New York |
| 3 | Alan | null |
Nom de fichier context.folder + "/json/customers.json", autres réglages par défaut. Code du tJava_1 :
File name context.folder + "/json/customers.json", other settings by default. tJava_1 code:
for (String line : java.nio.file.Files.readAllLines(java.nio.file.Paths.get(context.folder + "/json/customers.json"))) {
System.out.println(line);
}
System.out.println("NB_LINE: " + globalMap.get("tFileOutputJSON_1_NB_LINE"));
{"data":[{"city":"London","name":"Ada","id":1},{"city":"New York","name":"Grace","id":2},{"city":null,"name":"Alan","id":3}]}
NB_LINE: 3
Tout le fichier est sur une ligne, sans fin de ligne à la fin. Les clés ne suivent pas l'ordre du schéma (id, name, city) : le composant range chaque ligne dans une table de hachage. L'ordre obtenu est le même d'une ligne à l'autre. Un nombre est écrit sans guillemets, une valeur null comme null.
The whole file is on one line, with no line end at the end. Keys do not follow the schema order (id, name, city): the component stores each row in a hash table. The order obtained is the same from one row to the next. A number is written without quotes, a null value as null.
Mêmes lignes, case cochée : Same rows, box checked:
[{"city":"London","name":"Ada","id":1},{"city":"New York","name":"Grace","id":2},{"city":null,"name":"Alan","id":3}]
Le fichier est le tableau lui-même ; le Nom du bloc de données est masqué et sans effet. The file is the array itself; the Name of data block is hidden and has no effect.
Le tFixedFlowInput n'envoie aucune ligne. empty.json : réglages par défaut ; empty_array.json : Générer un tableau JSON coché.
The tFixedFlowInput sends no row. empty.json: default settings; empty_array.json: Generate an array json checked.
--- empty.json
{"data":[]}
--- empty_array.json
[]
Le fichier est toujours écrit, avec un tableau vide. The file is always written, with an empty array.
Une ligne, une colonne par type : One row, one column per type:
| ColonneColumn | Type | ValeurValue |
|---|---|---|
| text | String | Say "hi" / C:\temp, Montréal 10 € |
| born | Date, modèle "yyyy-MM-dd"Date, pattern "yyyy-MM-dd" | 1815-12-10 |
| updated | Date, sans modèleDate, no pattern | 2026-11-11 09:30 |
| amount | BigDecimal | 12.50 |
| ratio | Double | 0.5 |
| active | Boolean | true |
| initial | Character | A |
| count | Integer, non nullableInteger, not nullable | 3 |
{"data":[{"amount":12.50,"initial":"A","born":"1815-12-10","count":3,"active":true,"text":"Say \"hi\" \/ C:\\temp, Montréal 10 \u20AC","updated":Wed Nov 11 09:30:00 CET 2026,"ratio":0.5}]}
12.50). Un Character devient une chaîne.
Numbers and booleans are written without quotes; a BigDecimal keeps its decimals (12.50). A Character becomes a string.
toString() de Java, sans guillemets : le fichier n'est plus du JSON valide (voir les erreurs).
A Date with a pattern becomes a formatted string. Without a pattern, it is written by the Java toString(), without quotes: the file is no longer valid JSON (see the errors).
" devient \", \ devient \\, et / devient \/. é est gardé tel quel, mais € est écrit \u20AC. Ces trois formes sont du JSON valide, relu comme le texte d'origine.
In strings, " becomes \", \ becomes \\, and / becomes \/. é is kept as it is, but € is written \u20AC. These three forms are valid JSON, read back as the original text.
Le nom du job est remplacé par MyJob, le dossier de travail par C:\data ; les traces d'exception sont abrégées. La fin des messages vient de Windows, dans sa langue.
The job name is replaced with MyJob, the working folder with C:\data; exception traces are shortened. The end of the messages comes from Windows, in its language.
Dans l'exemple des types, la colonne updated n'a pas de modèle de date :
In the types example, the updated column has no date pattern:
"updated":Wed Nov 11 09:30:00 CET 2026
Le job finit sans erreur, mais un lecteur JSON refusera le fichier. Donnez un modèle à toutes les colonnes Date, par exemple "yyyy-MM-dd'T'HH:mm:ss".
The job ends with no error, but a JSON reader will reject the file. Give a pattern to all Date columns, for instance "yyyy-MM-dd'T'HH:mm:ss".
Nom de fichier context.folder + "/json/missing/out.json", dossier missing absent, Créer le répertoire s'il n'existe pas décoché : le job s'arrête (code 1).
File name context.folder + "/json/missing/out.json", missing folder absent, Create directory if it does not exist unchecked: the job stops (exit code 1).
Exception in component tFileOutputJSON_1 (MyJob) java.io.FileNotFoundException: C:\data\json\missing\out.json (Le chemin d’accès spécifié est introuvable) at java.base/java.io.FileOutputStream.open0(Native Method) …
L'ordre des clés ne suit pas le schéma. Un lecteur JSON n'en tient pas compte, mais deux fichiers ne se comparent pas comme du texte si leurs schémas diffèrent, et un lecteur qui lit les valeurs par position se trompe. The key order does not follow the schema. A JSON reader ignores it, but two files cannot be compared as text if their schemas differ, and a reader that reads values by position gets them wrong.
Le fichier prend l'encodage par défaut de Java : UTF-8 dans nos essais (Java 21), comme le veut JSON. Avec une option de lancement qui change cet encodage, les caractères accentués changent aussi ; un autre encodage s'obtient ensuite avec tChangeFileEncoding. The file takes the Java default encoding: UTF-8 in our tests (Java 21), as JSON requires. With a launch option that changes this encoding, accented characters change too; another encoding is obtained afterwards with tChangeFileEncoding.
Une ligne donne un objet d'un seul niveau. Pour des objets imbriqués ou des tableaux dans les objets, construisez le JSON avec d'autres composants (tWriteJSONField) ou dans un tJavaRow. A row gives a one-level object. For nested objects or arrays inside objects, build the JSON with other components (tWriteJSONField) or in a tJavaRow.
Le fichier n'est ni indenté, ni découpé en lignes, quel que soit le nombre d'objets. Pour le lire à l'œil, ouvrez-le dans un outil qui met le JSON en forme. The file is neither indented nor split into lines, whatever the number of objects. To read it by eye, open it in a tool that formats JSON.
tFileOutputXML · écrire les lignes en XMLwrite the rows as XMLtFileOutputDelimited · écrire les lignes dans un fichier délimitéwrite the rows to a delimited filetConvertType · convertir les colonnes avant l'écritureconvert the columns before writingtChangeFileEncoding · réécrire le fichier dans un autre encodagerewrite the file in another encodingtJavaRow · construire une valeur ligne par lignebuild a value row by rowtLogRow · afficher les lignes d'un fluxdisplay the rows of a flow