ComposantsComponents › Traitement › ChampsProcessing › Fields
Lit le document JSON contenu dans une colonne du flux (le corps d'une réponse REST, un champ d'une table, une ligne d'un fichier) et en tire des colonnes : une requête de boucle désigne les éléments répétés, chacun donne une ligne de sortie, et une requête par colonne lit chaque valeur dans l'élément. Les colonnes sans requête reprennent la colonne d'entrée de même nom. C'est le tFileInputJSON appliqué à une colonne ; pour construire du JSON, prenez un tWriteJSONField. Reads the JSON document held in a column of the flow (the body of a REST response, a field of a table, a line of a file) and extracts columns from it: a loop query designates the repeated elements, each one gives an output row, and a query per column reads each value in the element. The columns without a query take the input column of the same name. It is the tFileInputJSON applied to a column; to build JSON, take a tWriteJSONField.
EntréeInput
Main un flux, avec la colonne JSONone flow, with the JSON column
SortiesOutputs
Main obligatoire : une ligne par élément de la boucle.required: one row per loop element. Reject facultatif, masqué si Arrêter en cas d'erreur est coché : les lignes en erreur, avec errorJSONField et errorMessage.optional, hidden if Die on error is checked: the rows in error, with errorJSONField and errorMessage.
Déclencheurs en sortieOutput triggers
On Component Ok On Component Error Run if
Le tRESTClient, Convertir la réponse en document DOM décoché, met le JSON reçu dans sa colonne string : choisissez-la comme Champ JSON.
The tRESTClient, with Convert Response To DOM Document unchecked, puts the JSON received in its string column: choose it as JSON field.
Les autres colonnes de l'entrée (un identifiant, une date) se recopient dans chaque ligne produite : mettez-les dans le schéma de sortie, avec une requête vide. The other input columns (an identifier, a date) are copied into each row produced: put them in the output schema, with an empty query.
"$.items[*]"), puis la requête de chaque colonne, relative à l'élément de la boucle ("sku", "price"). Laissez vide la requête d'une colonne à reprendre de l'entrée.
Leave Read By on JsonPath, write the Loop Jsonpath query ("$.items[*]"), then the query of each column, relative to the loop element ("sku", "price"). Leave empty the query of a column to be taken from the input.
Le paramètre Lu par choisit le modèle de code généré ; chaque mode a sa requête de boucle, sa table Mapping et ses bibliothèques. The Read By setting chooses the generated code template; each mode has its own loop query, Mapping table and libraries.
Bibliothèque Jayway json-path (2.1.0, ou 1.2.0 selon Version de l'API) avec json-smart. La boucle donne la liste des éléments ($.items[*], $[*] pour un tableau à la racine, $ pour le document entier) ; chaque requête de colonne est lue dans l'élément courant : sku, customer.city, items[0].sku, un filtre items[?(@.qty > 1)].sku, une fonction tags.length().
Jayway json-path library (2.1.0, or 1.2.0 depending on API version) with json-smart. The loop gives the list of elements ($.items[*], $[*] for an array at the root, $ for the whole document); each column query is read in the current element: sku, customer.city, items[0].sku, a filter items[?(@.qty > 1)].sku, a function tags.length().
Une requête qui commence par $ part de l'élément de la boucle, sauf si Utiliser le nœud de boucle comme racine est décoché : elle part alors du document (voir l'exemple).
A query starting with $ starts from the loop element, unless Use the loop node as root is unchecked: it then starts from the document (see the example).
Le JSON est converti en XML (bibliothèque staxon), puis lu comme par un tExtractXMLField : boucle et colonnes en XPath (/items, ../customer/name). Chaque clé devient un élément ; un tableau devient des éléments répétés. Un tableau à la racine se lit avec la boucle "/".
The JSON is converted to XML (staxon library), then read as by a tExtractXMLField: loop and columns in XPath (/items, ../customer/name). Each key becomes an element; an array becomes repeated elements. An array at the root is read with the "/" loop.
Deux cases par colonne : Obtenir les nœuds rend l'élément entier en JSON, son nom compris ; Is Array rend toutes les valeurs trouvées, sous la forme [P1, P2] (voir l'exemple). Une valeur null du JSON y devient un texte vide.
Two boxes per column: Get Nodes returns the whole element as JSON, its name included; Is Array returns all the values found, in the form [P1, P2] (see the example). A JSON null value becomes an empty text there.
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Les requêtes sont des expressions Java : "$.items[*]", "sku", context.loop.
Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. Queries are Java expressions: "$.items[*]", "sku", context.loop.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Type de propriétéProperty TypePROPERTY | Built-inBuilt-In | ToujoursAlways | Built-in : les réglages sont saisis dans le composant. Référentiel : le mode de lecture, la boucle et les requêtes viennent d'une métadonnée JSON du Référentiel. Built-In: the settings are typed in the component. Repository: the read mode, the loop and the queries come from a JSON metadata of the Repository. |
| SchémaSchemaSCHEMA | — | ToujoursAlways |
Les colonnes de sortie, chacune remplie par sa requête et convertie dans son type. Le lien Reject a son propre schéma (SCHEMA_REJECT) : les mêmes colonnes, plus errorJSONField, errorCode et errorMessage (String, 255).
The output columns, each filled by its query and converted to its type. The Reject link has its own schema (SCHEMA_REJECT): the same columns, plus errorJSONField, errorCode and errorMessage (String, 255).
|
| Lu parRead ByREAD_BY | JSONPath | ToujoursAlways | JSONPath ou XPath (voir les modes). Chaque mode a ses propres paramètres de boucle et de mapping. JsonPath or Xpath (see the modes). Each mode has its own loop and mapping settings. |
| Version de l'APIAPI versionJSON_PATH_VERSION | 2.1.0 | JSONPathJsonPath |
Version de la bibliothèque json-path ajoutée au job : 2.1.0 ou 1.2.0. Le code généré est le même ; les deux ont donné le même résultat sur le premier exemple de cette page.
Version of the json-path library added to the job: 2.1.0 or 1.2.0. The generated code is the same; both gave the same result on the first example of this page.
|
| Champ JSONJSON fieldJSONFIELD | — | ToujoursAlways |
La colonne d'entrée qui contient le JSON, lue par toString(). Une ligne dont cette colonne est null est ignorée : rien en sortie, rien en rejet, rien compté.
The input column holding the JSON, read with toString(). A row whose column is null is ignored: nothing out, nothing rejected, nothing counted.
|
| Requête de boucle JSONPathLoop Jsonpath queryJSON_LOOP_QUERY | "$.bills.bill.line[*]" |
JSONPathJsonPath | Les éléments à parcourir, une ligne de sortie par élément. Un tableau vide ne donne aucune ligne ; une requête qui désigne un seul objet en donne une. The elements to go through, one output row per element. An empty array gives no row; a query designating a single object gives one. |
| Requête XPath boucleLoop XPath queryLOOP_QUERY | "/bills/bill/line" |
XPath |
La même chose en XPath, sur le JSON converti en XML : "/items" pour les éléments du tableau items, "/" pour le document entier ou les éléments d'un tableau à la racine.
The same in XPath, on the JSON converted to XML: "/items" for the elements of the items array, "/" for the whole document or the elements of an array at the root.
|
| MappingMAPPING_4_JSONPATH | une ligne par colonneone row per column | JSONPathJsonPath | Pour chaque colonne du schéma, sa Requête JSON, relative à l'élément de la boucle. Vide : la colonne reprend la colonne d'entrée de même nom. For each schema column, its Json query, relative to the loop element. Empty: the column takes the input column of the same name. |
| MappingMAPPING | une ligne par colonneone row per column | XPath | Pour chaque colonne : Requête XPath (vide : colonne d'entrée de même nom), Obtenir les nœuds (l'élément trouvé, rendu en JSON) et Is Array (toutes les valeurs trouvées, pour une colonne String, List ou Object). For each column: XPath query (empty: input column of the same name), Get Nodes (the element found, returned as JSON) and Is Array (all the values found, for a String, List or Object column). |
| Arrêter en cas d'erreurDie on errorDIE_ON_ERROR | NonNo | ToujoursAlways | Cochée, la première erreur (JSON mal formé, valeur qui ne se convertit pas) arrête le job. Décochée, la ligne en erreur part au lien Reject, ou, sans lien Reject, son message va sur la sortie d'erreur et elle est écartée (voir les erreurs). Checked, the first error (malformed JSON, value that does not convert) stops the job. Unchecked, the row in error goes to the Reject link, or, without a Reject link, its message goes to the error output and it is dropped (see the errors). |
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Version JDKJDK versionJDK_VERSION | JDK 8 à 11JDK 8 to 11 | XPath |
JDK 11 et supérieures ajoute au job les bibliothèques Nashorn (nashorn-core-15.4) et ASM 9.5. Le code de ce composant ne s'en sert pas : tous les exemples XPath de cette page ont gardé la valeur par défaut, dans des jobs exécutés dans Talaxie (Java 21).
JDK11 and above adds the Nashorn (nashorn-core-15.4) and ASM 9.5 libraries to the job. The code of this component does not use them: all the XPath examples of this page kept the default value, in jobs run in Talaxie (Java 21).
|
| EncodageEncodingENCODING | "UTF-8" |
XPath | L'encodage de la conversion du JSON en XML. Gardez UTF-8 : avec un autre encodage, le composant ne lit plus rien (voir les erreurs). The encoding of the conversion of the JSON to XML. Keep UTF-8: with another encoding, the component no longer reads anything (see the errors). |
| Utiliser le nœud de boucle comme racineUse the loop node as rootUSE_LOOP_AS_ROOT | OuiYes | JSONPathJsonPath |
Cochée, toutes les requêtes de colonne sont lues dans l'élément de la boucle, $ compris. Décochée, une requête qui commence par $ est lue dans le document entier : pour reprendre dans chaque ligne une valeur au-dessus de la boucle (numéro de commande, client).
Checked, all the column queries are read in the loop element, $ included. Unchecked, a query starting with $ is read in the whole document: to repeat in each row a value above the loop (order number, customer).
|
NB_LINE (Integer, disponible après l'exécution du composant) : nombre d'éléments de boucle traités, y compris ceux dont une valeur ne s'est pas convertie. Un JSON mal formé et une colonne JSON null ne comptent pas (3 pour 5 lignes reçues dans l'exemple des erreurs).
NB_LINE (Integer, available after the component has run): number of loop elements processed, including those with a value that did not convert. A malformed JSON and a null JSON column do not count (3 for 5 received rows in the errors example).
ERROR_MESSAGE (String), que le composant ne déclare pas : le message de la dernière erreur, ou de la dernière valeur introuvable (No results for path: $['order']), même quand le job s'est bien passé.
ERROR_MESSAGE (String), which the component does not declare: the message of the last error, or of the last value not found (No results for path: $['order']), even when the job went well.
((Integer) globalMap.get("tExtractJSONFields_1_NB_LINE"))
((String) globalMap.get("tExtractJSONFields_1_ERROR_MESSAGE"))
Un tFixedFlowInput envoie des lignes id (Integer), json (String) au tExtractJSONFields_1, dont la sortie est affichée par un tLogRow (en tableau), ou par un tJavaRow qui écrit chaque valeur entre crochets pour distinguer null du texte vide. Un tJava relié par On Subjob Ok affiche les variables globales :
A tFixedFlowInput sends rows id (Integer), json (String) to tExtractJSONFields_1, whose output is printed by a tLogRow (as a table), or by a tJavaRow that writes each value between brackets to tell null from the empty text. A tJava connected with On Subjob Ok prints the global variables:
System.out.println("tExtractJSONFields_1_NB_LINE: " + globalMap.get("tExtractJSONFields_1_NB_LINE"));
System.out.println("tExtractJSONFields_1_ERROR_MESSAGE: " + globalMap.get("tExtractJSONFields_1_ERROR_MESSAGE"));
Quand un job enchaîne plusieurs sous-jobs, un tJava affiche avant chacun une ligne === …. Les sorties sont copiées depuis des exécutions des jobs dans Talaxie (Java 21). Les trois commandes d'entrée de la plupart des exemples :
When a job chains several subjobs, a tJava prints a === … line before each one. The outputs are copied from runs of the jobs in Talaxie (Java 21). The three input orders of most examples:
id=1 {"order":"A-1","customer":{"name":"Ada","city":"London"},"items":[{"sku":"P1","qty":2,"price":9.5},{"sku":"P2","qty":1,"price":20}]}
id=2 {"order":"A-2","customer":{"name":"Alan"},"items":[{"sku":"P3","qty":5,"price":null}]}
id=3 {"order":"A-3","customer":{"name":"Grace","city":"New York"},"items":[]}
Boucle "$.items[*]", réglages par défaut. Mapping : id vide, sku "sku", qty (Integer) "qty", price (Double) "price", order "$.order".
"$.items[*]" loop, default settings. Mapping: id empty, sku "sku", qty (Integer) "qty", price (Double) "price", order "$.order".
.--+---+---+-----+-----. | tLogRow_1 | |=-+---+---+-----+----=| |id|sku|qty|price|order| |=-+---+---+-----+----=| |1 |P1 |2 |9.5 |null | |1 |P2 |1 |20.0 |null | |2 |P3 |5 |null |null | '--+---+---+-----+-----' tExtractJSONFields_1_NB_LINE: 3 tExtractJSONFields_1_ERROR_MESSAGE: No results for path: $['order']
Trois articles, trois lignes ; la commande A-3, au tableau vide, n'en donne aucune. id est recopié de l'entrée dans chaque ligne. Le null du JSON donne null. order reste null : par défaut, $ est l'article, qui n'a pas de clé order.
Three items, three rows; order A-3, with its empty array, gives none. id is copied from the input into each row. The JSON null gives null. order stays null: by default, $ is the item, which has no order key.
Même boucle, Utiliser le nœud de boucle comme racine décoché. Mapping : id vide, sku, qty, puis "$.order", "$.customer.name", "$.customer.city".
Same loop, Use the loop node as root unchecked. Mapping: id empty, sku, qty, then "$.order", "$.customer.name", "$.customer.city".
.--+---+---+-----+----+------. | tLogRow_1 | |=-+---+---+-----+----+-----=| |id|sku|qty|order|name|city | |=-+---+---+-----+----+-----=| |1 |P1 |2 |A-1 |Ada |London| |1 |P2 |1 |A-1 |Ada |London| |2 |P3 |5 |A-2 |Alan|null | '--+---+---+-----+----+------' tExtractJSONFields_1_NB_LINE: 3 tExtractJSONFields_1_ERROR_MESSAGE: No results for path: $['customer']['city']
Les requêtes en $ partent du document de la ligne ; les autres, de l'article. La ville absente d'Alan donne null, et son message reste dans ERROR_MESSAGE.
The $ queries start from the document of the row; the others, from the item. Alan's missing city gives null, and its message stays in ERROR_MESSAGE.
null ou videMissing, null or empty value
Boucle "$" (le document est la ligne). Colonnes name et city (String), age (Integer), agedef (Integer, valeur par défaut -1 dans le schéma) et agenn (Integer, non nullable), ces deux dernières sur "age". Entrée :
"$" loop (the document is the row). Columns name and city (String), age (Integer), agedef (Integer, default value -1 in the schema) and agenn (Integer, not nullable), the last two on "age". Input:
id=1 {"name":"Ada","age":36,"city":"London"}
id=2 {"name":"Grace","age":null,"city":null}
id=3 {"name":"Linus"}
id=4 {"name":"","age":"","city":""}
id=[1] name=[Ada] age=[36] city=[London] agedef=[36] agenn=[36] id=[2] name=[Grace] age=[null] city=[null] agedef=[-1] agenn=[0] id=[3] name=[Linus] age=[null] city=[null] agedef=[-1] agenn=[0] id=[4] name=[] age=[null] city=[] agedef=[-1] agenn=[0] tExtractJSONFields_1_NB_LINE: 4 tExtractJSONFields_1_ERROR_MESSAGE: No results for path: $['age']
Clé absente et valeur null donnent la même chose : la valeur par défaut de la colonne, sinon null, ou 0 pour un entier non nullable. Un texte vide reste vide dans une colonne String ; dans une colonne numérique, il compte comme absent. Aucune ligne n'est rejetée.
Missing key and null value give the same thing: the default value of the column, otherwise null, or 0 for a non-nullable integer. An empty text stays empty in a String column; in a numeric column, it counts as missing. No row is rejected.
Quatre sous-jobs : boucle "$[*]" sur [{"sku":"P1","qty":2},{"sku":"P2","qty":1}] (id 1) et [] (id 2) ; boucle "$.tags[*]" sur {"tags":["red","blue"]}, requête "$" ; boucle "$[*]" sur ["red","blue"], requête "@" ; boucle "$" sur le premier, requête "tags".
Four subjobs: "$[*]" loop on [{"sku":"P1","qty":2},{"sku":"P2","qty":1}] (id 1) and [] (id 2); "$.tags[*]" loop on {"tags":["red","blue"]}, "$" query; "$[*]" loop on ["red","blue"], "@" query; "$" loop on the first one, "tags" query.
=== loop $[*] on a root array 1|P1|2 1|P2|1 === loop $.tags[*], query $ 1|red 1|blue === loop $[*] on an array of strings, query @ 2|red 2|blue === loop $ on an object 1|["red","blue"] tExtractJSONFields_1_NB_LINE: 2 tExtractJSONFields_2_NB_LINE: 2 tExtractJSONFields_3_NB_LINE: 2 tExtractJSONFields_4_NB_LINE: 1
Pour un tableau de textes ou de nombres, la valeur elle-même se lit par "$" ou "@". Un tableau lu dans une colonne String sort en JSON.
For an array of texts or numbers, the value itself is read with "$" or "@". An array read into a String column comes out as JSON.
Boucle "$" sur {"name":"Ada","address":{"city":"London","zip":"N1"},"tags":["a","b"],"items":[{"sku":"P1","qty":2},{"sku":"P2","qty":1}]}. Requêtes : "address", "tags", "items[*].sku", "items[0].sku", "items[?(@.qty > 1)].sku" (String) et "tags.length()" (Integer).
"$" loop on {"name":"Ada","address":{"city":"London","zip":"N1"},"tags":["a","b"],"items":[{"sku":"P1","qty":2},{"sku":"P2","qty":1}]}. Queries: "address", "tags", "items[*].sku", "items[0].sku", "items[?(@.qty > 1)].sku" (String) and "tags.length()" (Integer).
address=[{"zip":"N1","city":"London"}] tags=[["a","b"]] skus=[["P1","P2"]] first=[P1] big=[["P1"]] count=[2]
Un objet ou un tableau sort en JSON compact. L'ordre des clés d'un objet n'est pas gardé (zip avant city). Un filtre rend toujours un tableau, même d'un seul élément.
An object or an array comes out as compact JSON. The order of the keys of an object is not kept (zip before city). A filter always returns an array, even of a single element.
Boucle sur le document {"born":"1815-12-10","active":true,"amount":12345678901234567.89,"rate":0.1,"big":3000000000,"n":1}, colonnes born (Date, motif "yyyy-MM-dd"), active (Boolean), amount et rate (BigDecimal), big (Long), dans les deux modes.
Loop on the document {"born":"1815-12-10","active":true,"amount":12345678901234567.89,"rate":0.1,"big":3000000000,"n":1}, columns born (Date, pattern "yyyy-MM-dd"), active (Boolean), amount and rate (BigDecimal), big (Long), in both modes.
=== JsonPath born=[Sun Dec 10 00:00:00 CET 1815] active=[true] amount=[12345678901234567.89] rate=[0.1] big=[3000000000] === XPath born=[Sun Dec 10 00:00:00 CET 1815] active=[true] amount=[12345678901234567.89] rate=[0.1] big=[3000000000]
Les valeurs sont converties depuis leur texte : un grand décimal garde tous ses chiffres. Une date se lit avec le motif de la colonne (affichée ici par Date.toString()).
Values are converted from their text: a large decimal keeps all its digits. A date is read with the pattern of the column (printed here by Date.toString()).
Les trois commandes, Lu par XPath, boucle "/items". Requêtes : id vide, "sku", "qty", "price", "../order", "../customer/name", "../customer/city".
The three orders, Read By Xpath, "/items" loop. Queries: id empty, "sku", "qty", "price", "../order", "../customer/name", "../customer/city".
.--+---+---+-----+-----+----+------. | tLogRow_1 | |=-+---+---+-----+-----+----+-----=| |id|sku|qty|price|order|name|city | |=-+---+---+-----+-----+----+-----=| |1 |P1 |2 |9.5 |A-1 |Ada |London| |1 |P2 |1 |20.0 |A-1 |Ada |London| |2 |P3 |5 |null |A-2 |Alan|null | '--+---+---+-----+-----+----+------' tExtractJSONFields_1_NB_LINE: 3 tExtractJSONFields_1_ERROR_MESSAGE: null
Le même résultat qu'en JSONPath, en remontant par .. au lieu de décocher une case. Une valeur absente n'est pas une erreur en XPath : ERROR_MESSAGE reste null.
The same result as in JsonPath, going up with .. instead of unchecking a box. A missing value is not an error in XPath: ERROR_MESSAGE stays null.
Les deux premières commandes, boucle "/", colonnes String : "order" ; "items/sku" ; la même avec Is Array ; "customer" avec Obtenir les nœuds ; "items/price".
The first two orders, "/" loop, String columns: "order"; "items/sku"; the same with Is Array; "customer" with Get Nodes; "items/price".
order=[A-1] first=[P1] skus=[[P1, P2]] customer=[{"customer":{"name":"Ada","city":"London"}}] price=[9.5]
order=[A-2] first=[P3] skus=[[P3]] customer=[{"customer":{"name":"Alan"}}] price=[]
Sans Is Array, une requête qui trouve plusieurs éléments rend le premier. Obtenir les nœuds rend l'objet avec sa clé. Le prix null d'A-2 donne un texte vide, là où JSONPath donne null.
Without Is Array, a query that finds several elements returns the first one. Get Nodes returns the object with its key. The null price of A-2 gives an empty text, where JsonPath gives null.
Tableau à la racine (boucle "/"), objet à une seule clé (boucle "/items"), puis {"name":null,"city":"","age":null,"n":1} lu par la boucle "/" :
Array at the root ("/" loop), object with a single key ("/items" loop), then {"name":null,"city":"","age":null,"n":1} read by the "/" loop:
=== XPath, loop /, root array id=[1] sku=[P1] qty=[2] id=[1] sku=[P2] qty=[null] id=[2] sku=[P3] qty=[1] === XPath, loop /items, single key id=[1] sku=[P1] id=[1] sku=[P2] id=[2] sku=[P3] === XPath, null and empty name=[] city=[] age=[null]
Entrées : id 1 [{"sku":"P1","qty":2},{"sku":"P2","qty":null}], id 2 [{"sku":"P3","qty":1}] ; puis id 1 {"items":[{"sku":"P1"},{"sku":"P2"}]}, id 2 {"items":[{"sku":"P3"}]}. En XPath, une colonne String ne distingue pas null du texte vide.
Inputs: id 1 [{"sku":"P1","qty":2},{"sku":"P2","qty":null}], id 2 [{"sku":"P3","qty":1}]; then id 1 {"items":[{"sku":"P1"},{"sku":"P2"}]}, id 2 {"items":[{"sku":"P3"}]}. In XPath, a String column does not tell null from the empty text.
Le nom du job est remplacé par MyJob et les traces d'exception sont abrégées. Cinq lignes d'entrée, boucle "$", colonnes id (requête vide), name et age (Integer) ; les tLogRow affichent leur nom devant chaque ligne :
The job name is replaced with MyJob and exception traces are shortened. Five input rows, "$" loop, columns id (empty query), name and age (Integer); the tLogRow components print their name in front of each row:
id=1 {"name":"Ada","age":36}
id=2 {"name":"Alan","age":"forty"}
id=3 {"name":"Grace"
id=4 null
id=5 {"name":"Linus","age":28}
[tLogRow_1] 1|Ada|36
[tLogRow_2] 2|Alan||{"name":"Alan","age":"forty"}||For input string: "forty" - Line: 1
[tLogRow_2] 3|||{"name":"Grace"||net.minidev.json.parser.ParseException: Unexpected End Of File position 14: null - Line: 2
[tLogRow_1] 5|Linus|28
tExtractJSONFields_1_NB_LINE: 3
tExtractJSONFields_1_ERROR_MESSAGE: net.minidev.json.parser.ParseException: Unexpected End Of File position 14: null
Colonnes du rejet : id, name, age, errorJSONField (le JSON reçu), errorCode, errorMessage. La ligne 2 garde ce qui a été lu avant l'erreur ; la ligne 3, au JSON mal formé, n'a que les colonnes recopiées de l'entrée. La ligne 4, au JSON null, disparaît sans message. Line est le nombre de lignes déjà traitées par le composant (éléments de boucle et JSON mal formés), pas un numéro de ligne d'entrée.
Reject columns: id, name, age, errorJSONField (the JSON received), errorCode, errorMessage. Row 2 keeps what was read before the error; row 3, with its malformed JSON, only has the columns copied from the input. Row 4, with a null JSON, disappears without a message. Line is the number of rows already processed by the component (loop elements and malformed JSON), not an input row number.
Défaut du modèle de Talaxie : errorCode n'est rempli dans aucun mode.
Defect of the Talaxie template: errorCode is filled in no mode.
Sans lien Reject, les lignes en erreur sont écartées et leur message va sur la sortie d'erreur : Without a Reject link, the rows in error are dropped and their message goes to the error output:
[tLogRow_1] 1|Ada|36 For input string: "forty" net.minidev.json.parser.ParseException: Unexpected End Of File position 14: null [tLogRow_1] 5|Linus|28 tExtractJSONFields_1_NB_LINE: 3 tExtractJSONFields_1_ERROR_MESSAGE: net.minidev.json.parser.ParseException: Unexpected End Of File position 14: null
Arrêter en cas d'erreur coché : le job s'arrête à la ligne 2 (code de sortie 1). Die on error checked: the job stops at row 2 (exit code 1).
[tLogRow_1] 1|Ada|36 Exception in component tExtractJSONFields_1 (MyJob) java.lang.NumberFormatException: For input string: "forty" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67) … at routines.system.ParserUtils.parseTo_Integer(ParserUtils.java:137) …
Mêmes lignes, Lu par XPath, boucle "/", lien Reject. Seul le message du JSON mal formé change :
Same rows, Read By Xpath, "/" loop, Reject link. Only the message of the malformed JSON changes:
[tLogRow_1] 1|Ada|36
[tLogRow_2] 2|Alan||{"name":"Alan","age":"forty"}||For input string: "forty" - Line: 1
[tLogRow_2] 3|||{"name":"Grace"||Found starting '{' but missing '}' at the end. at character 0 of null - Line: 2
[tLogRow_1] 5|Linus|28
tExtractJSONFields_1_NB_LINE: 3
tExtractJSONFields_1_ERROR_MESSAGE: Found starting '{' but missing '}' at the end. at character 0 of null
Mode XPath, boucle "/", deux lignes {"name":"Café","city":"Zürich","n":1} et {"name":"Cafe","city":"Zurich","n":1}, avec l'Encodage par défaut, puis "ISO-8859-15", puis en JSONPath :
XPath mode, "/" loop, two rows {"name":"Café","city":"Zürich","n":1} and {"name":"Cafe","city":"Zurich","n":1}, with the default Encoding, then "ISO-8859-15", then in JsonPath:
=== XPath UTF-8 name=[Café] city=[Zürich] name=[Cafe] city=[Zurich] === XPath ISO-8859-15 Error on line 1 of document : Fin prématurée du fichier. Error on line 1 of document : Fin prématurée du fichier. === JsonPath name=[Café] city=[Zürich] name=[Cafe] city=[Zurich]
Défaut du modèle de Talaxie : le texte XML est lu avant la fin de la conversion, qui n'est écrite à temps qu'en UTF-8. Avec un autre encodage, même sans accent, aucune ligne ne sort et le job finit sans erreur (code 0) ; la fin du message (Premature end of file.) vient de Java, dans la langue du système. Gardez UTF-8, ou prenez le mode JSONPath, qui n'a pas ce réglage. Defect of the Talaxie template: the XML text is read before the end of the conversion, which is only written in time in UTF-8. With another encoding, even without accents, no row comes out and the job ends without error (exit code 0); the end of the message (Premature end of file.) comes from Java, in the language of the system. Keep UTF-8, or take the JsonPath mode, which has no such setting.
Une ligne dont le Champ JSON est null ne produit rien, même pas un rejet, et n'est pas comptée. Si ces lignes comptent, séparez-les avant par un tFilterRow.
A row whose JSON field is null produces nothing, not even a reject, and is not counted. If these rows matter, separate them before with a tFilterRow.
ERROR_MESSAGE n'indique pas un échecERROR_MESSAGE does not mean a failure
En JSONPath, une valeur absente (null en sortie, sans rejet) remplit aussi ERROR_MESSAGE. Pour savoir s'il y a eu des rejets, comptez les lignes du lien Reject.
In JsonPath, a missing value (null out, without reject) also fills ERROR_MESSAGE. To know whether there were rejects, count the rows of the Reject link.
Le mode JSONPath n'utilise que des bibliothèques publiques de Maven Central (com.jayway.jsonpath:json-path, net.minidev:json-smart, accessors-smart, slf4j), et pas le jsonpath.jar propre à Talend dont a besoin le mode sans boucle du tFileInputJSON. Le mode XPath ajoute staxon, dom4j, jaxen et json-lib ; deux de ses bibliothèques sont propres à Talend (json-lib-2.4.8-talend, xom-1.2.7) : Talaxie les télécharge depuis son propre dépôt.
The JsonPath mode only uses public libraries from Maven Central (com.jayway.jsonpath:json-path, net.minidev:json-smart, accessors-smart, slf4j), and not the Talend-specific jsonpath.jar needed by the mode without loop of the tFileInputJSON. The XPath mode adds staxon, dom4j, jaxen and json-lib; two of its libraries are Talend-specific (json-lib-2.4.8-talend, xom-1.2.7): Talaxie downloads them from its own repository.
JSONPath distingue null du texte vide, a des filtres et des fonctions, et lit le JSON tel quel : une clé comme first name s'y écrit "['first name']". XPath sait remonter (..) et rendre un élément entier, mais une seule clé qui n'est pas un nom XML (first name, 1st) rend tout le document illisible : aucune ligne, et Error on line 1 of document sur la sortie d'erreur.
JsonPath tells null from the empty text, has filters and functions, and reads the JSON as it is: a key like first name is written "['first name']" there. XPath can go up (..) and return a whole element, but a single key that is not an XML name (first name, 1st) makes the whole document unreadable: no row, and Error on line 1 of document on the error output.
tWriteJSONField · construire une colonne JSONbuild a JSON columntFileInputJSON · les mêmes requêtes sur un fichierthe same queries on a filetExtractXMLField · extraire des champs d'une colonne XMLextract fields from an XML columntExtractRegexFields · découper une colonne par une expression régulièresplit a column with a regular expressiontExtractDelimitedFields · découper une colonne délimitéesplit a delimited columntRESTClient · appeler un service RESTcall a REST service