---
sourceDocument: Référence API Brésil
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/api-reference

 Release :

    - brazil

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence API Brésil

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# JSONStreamingBuilder : délimité

# JSONStreamingBuilder : délimité {#ariaid-title1}

Rversion finale: Brazil  
Mis à jour 10 sept. 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 7 minutes de lecture  
Créez un objet de générateur utilisé pour construire une charge utile JSON de diffusion volumineuse à utiliser dans une demande REST ou SOAP pour envoyer des données en bloc à une API tierce. Vous pouvez également créer la charge utile en tant que chaîne JSON pour une option de non-diffusion en continu.
Utilisez ces méthodes à l'étape Script Studio de workflow avec l'identificateur `d'espace` de noms sn_ih. Par exemple, vous pouvez utiliser cette API pour créer une charge utile JSON à l'étape Studio de workflow Script et transmettre la valeur renvoyée à l'étape REST pour envoyer la demande à un service tiers. Pour plus d'informations, consultez Studio de workflow [l'étape Script](https://www.servicenow.com/docs/access?context=javascript-step-action-designer&version=brazil&pubname=brazil-build-workflows&ft:locale=en-US).

Vous ne pouvez utiliser cette API qu'au sein de l'environnement Studio de workflow .

## Ordre d'appel d'API {#JSONStreamingBuilderScopedAPI__section_owy_pd5_hlb}

Générez les charges utiles JSON à l'aide de ces API dans l'ordre suivant :  

JSONStreamingBuilder : crée un objet de générateur
:   Utilisez ces méthodes dans l'ordre suivant pour créer un objet de générateur :  
    1. JSONStreamingBuilder() : instancie l'objet JSONStreamingBuilder.{#JSONStreamingBuilderScopedAPI__json-api-constructor}
    2. withAttachment() : Facultatif. Crée l'objet JSON en tant que pièce jointe de diffusion et le stocke dans la table Pièces jointes de diffusion en continu \[streaming_attachment\]. Si vous n'appelez pas cette méthode, l'API crée la charge utile sous forme de chaîne JSON.{#JSONStreamingBuilderScopedAPI__with-attachments}
    3. expiresAt() : Facultatif. Définit une date d'expiration de la pièce jointe. Doit également appeler la méthode withAttachment( ).{#JSONStreamingBuilderScopedAPI__expires-at}
    4. build() : Renvoie un objet JSONStreamingAPI.{#JSONStreamingBuilderScopedAPI__build}
    {#JSONStreamingBuilderScopedAPI__ol_obn_dd5_hlb}

JSONStreamingAPI : génère la charge utile JSON
:   Utilisez ces méthodes dans l'ordre suivant pour créer la charge utile JSON :  
    1. startObject() : crée l'objet JSON parent.{#JSONStreamingBuilderScopedAPI__start-object}
    2. Méthodes pour générer les paires clé-valeur JSON, telles que writeFieldName(), writeString() et writeNumberField().
    3. endObject() : ferme l'objet JSON parent.{#JSONStreamingBuilderScopedAPI__end-object}
    4. getJSONString() ou getAttachmentId() : renvoie la chaîne JSON ou l'ID de pièce jointe que vous avez créé.
    5. close() : ferme l'objet JSONStreamingAPI.{#JSONStreamingBuilderScopedAPI__close}
    {#JSONStreamingBuilderScopedAPI__ol_yzk_qgn_hlb}

## Limites de taille {#JSONStreamingBuilderScopedAPI__section_qkj_sd5_hlb}

Les charges utiles générées via cette API ne peuvent pas dépasser ces limites de taille :  
* Pièces jointes : 200 Mo
* Chaînes : 5 Mo
{#JSONStreamingBuilderScopedAPI__ul_llq_msw_3lb}

## Exemples {#JSONStreamingBuilderScopedAPI__section_nzz_rd5_hlb}

Cet exemple montre comment créer un objet JSON et le stocker dans la table Pièce jointe \[sys_attachment\] avec une date d'expiration définie.  

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

Cet exemple montre également comment utiliser l'API à l'étape Script et créer la charge utile en tant que chaîne JSON. Vous pouvez utiliser cette option pour créer des charges utiles de moins de 5 Mo.  

    (function execute(inputs, outputs) {

      var builder = new sn_ih.JSONStreamingBuilder().build();
      
      builder.startObject()
        .enablePrettyPrint()
        .writeTextElement("firstName","John")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
          .writeStringField("streetAddress", "21 2nd Street")
          .writeStringField("city", "Santa Clara")
          .writeStringField("state", "CA")
          .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
          .startObject()
            .writeFieldName("type")
            .writeString("home")
            .writeFieldName("number")
            .writeString("212 555-1234")
          .endObject()
          .startObject()
            .writeFieldName("type")
            .writeString("fax")
            .writeFieldName("number")
            .writeString("646 555-4567")
          .endObject()
        .endArray()
        .endObject()

      outputs.payload = builder.getJSONString();
      
    })(inputs, outputs);

Sortie :  

    {
    "firstName" : "John",
    "lastName" : "Smith",
    "age" : 25,
    "address" : {
      "streetAddress" : "21 2nd Street",
      "city" : "Santa Clara",
      "state" : "CA",
      "postalCode" : "11111"
    },
    "phoneNumber" : [ {
      "type" : "home",
      "number" : "212 555-1234"
    }, {
      "type" : "fax",
      "number" : "646 555-4567"
    } ]
    }

## JSONStreamingBuilder : JSONStreamingBuilder() {#ariaid-title2}

instancie l'objet JSONStreamingBuilder.
{#JSB-JSONStreamingBuilder__table_mkq_q22_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 1. Paramètres]

{#JSB-JSONStreamingBuilder__table_mkq_q22_1lb}  

    var builder = new sn_ih.JSONStreamingBuilder()

## JSONStreamingBuilder : build() {#ariaid-title3}

Renvoie un objet JSONStreamingAPI.
{#JSB-build__table_g3z_zf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 2. Paramètres]

{#JSB-build__table_g3z_zf2_1lb} {#JSB-build__table_h3z_zf2_1lb__entry__2}

| Type | Description |
|-|-|
| API d'exécution JSON | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 3. Renvoie]

{#JSB-build__table_h3z_zf2_1lb}  
Cet exemple montre comment créer un objet JSON et le stocker dans la table Pièce jointe \[sys_attachment\] avec une date d'expiration définie.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingBuilder : expiresAt(Objet expiresAt) {#ariaid-title4}

Définit une date d'expiration de la pièce jointe. Doit également appeler la méthode withAttachment( ). Si vous n'appelez pas cette méthode, la pièce jointe expire deux heures après sa création.
{#JSB-expiresAt_O__table_wlk_hzt_hlb__entry__3}

| Nom | Type | Description |
|-|-|-|
| expiresAt | [GlideDateTime](https://servicenow-prod.fluidtopics.net/d2Z779N0LLPQ1Obl2IQ~JQ#c_GlideDateTimeScoped "La classe GlideDateTime incluse dans le champ d’application fournit des méthodes pour effectuer des opérations sur les objets GlideDateTime.") | Objet défini lorsque la pièce jointe expire. * Valeur minimale : 7 200 secondes, ou deux heures, à partir du moment où la pièce jointe est créée. Par défaut. * Valeur maximale : 172 800 secondes, ou 48 heures, à partir du moment où la pièce jointe est créée. {#JSB-expiresAt_O__ul_xsc_trx_3lb} |
[Tableau 4. Paramètres]

{#JSB-expiresAt_O__table_wlk_hzt_hlb} {#JSB-expiresAt_O__table_xlk_hzt_hlb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingBuilder | Objet de générateur utilisé pour lancer la charge utile JSON. |
[Tableau 5. Renvoie]

{#JSB-expiresAt_O__table_xlk_hzt_hlb}  
Cet exemple montre comment créer un objet JSON et le stocker dans la table Pièce jointe \[sys_attachment\] avec une date d'expiration définie.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingBuilder : withAttachment() {#ariaid-title5}

Crée l'objet JSON en tant que pièce jointe de diffusion et le stocke dans la table Pièces jointes de diffusion en continu \[streaming_attachment\]. Si vous n'appelez pas cette méthode, l'API crée la charge utile sous forme de chaîne JSON.
{#JSB-withAttachment__table_fm2_dzt_hlb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 6. Paramètres]

{#JSB-withAttachment__table_fm2_dzt_hlb} {#JSB-withAttachment__table_gm2_dzt_hlb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingBuilder | Objet de générateur utilisé pour lancer la charge utile JSON. |
[Tableau 7. Renvoie]

{#JSB-withAttachment__table_gm2_dzt_hlb}  
Cet exemple montre comment créer la charge utile JSON et l'enregistrer en tant que pièce jointe.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

Cet exemple montre comment créer la charge utile JSON et l'enregistrer en tant que chaîne.

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

Sortie :

    {
    "firstName" : "John",
    "lastName" : "Smith",
    "age" : 25,
    "address" : {
      "streetAddress" : "21 2nd Street",
      "city" : "Santa Clara",
      "state" : "CA",
      "postalCode" : "11111"
    },
    "phoneNumber" : [ {
      "type" : "home",
      "number" : "212 555-1234"
    }, {
      "type" : "fax",
      "number" : "646 555-4567"
    } ]
    }


