---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# JSONStreamingAPI - Dans le champ d'application

# JSONStreamingAPI - Dans le champ d'application {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 20 minutes de lecture

Créez 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 autre que la diffusion en continu.
Utilisez ces méthodes dans l'étape de Studio de workflow script avec l'identificateur `d'espace` de noms sn_ih. Par exemple, vous pouvez utiliser cette API pour créer une charge utile JSON dans 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, reportez-vous à Studio de workflow [l'étape Script](https://www.servicenow.com/docs/access?context=javascript-step-action-designer&version=xanadu&pubname=xanadu-build-workflows&ft:locale=en-US).

Vous ne pouvez utiliser cette API que dans l'environnement Studio de workflow .

Pour utiliser cette classe, vous devez appeler la méthode build() dans la classe JSONStreamingBuilder pour retourner un objet JSONStreamingAPI. Consultez [JSONStreamingBuilder - Dans le champ d'application](https://servicenow-prod.fluidtopics.net/Sqpv2xkEx0dYSQLZrtbmaA#JSONStreamingBuilderScopedAPI "Créez un objet de générateur utilisé pour générer 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 autre que la diffusion en continu.").

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

Générez des 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.{#JSONStreamingAPIScopedAPI__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 \[streaming_attachment\]. Si vous n'appelez pas cette méthode, l'API crée la charge utile sous la forme d'une chaîne JSON.{#JSONStreamingAPIScopedAPI__with-attachments}
    3. expiresAt() : Optionnel. Définit une heure à laquelle la pièce jointe expire. Doit également appeler la méthode withAttachment().{#JSONStreamingAPIScopedAPI__expires-at}
    4. build() : Renvoie un objet JSONStreamingAPI.{#JSONStreamingAPIScopedAPI__build}
    {#JSONStreamingAPIScopedAPI__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.{#JSONStreamingAPIScopedAPI__start-object}
    2. Méthodes permettant de générer les paires clé-valeur JSON, telles que writeFieldName(),writeString() et writeNumberField().
    3. endObject() : ferme l'objet JSON parent.{#JSONStreamingAPIScopedAPI__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.{#JSONStreamingAPIScopedAPI__close}
    {#JSONStreamingAPIScopedAPI__ol_yzk_qgn_hlb}

## Limites de taille {#JSONStreamingAPIScopedAPI__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
{#JSONStreamingAPIScopedAPI__ul_syy_lsw_3lb}

## Exemple {#JSONStreamingAPIScopedAPI__section_nzz_rd5_hlb}

Cet exemple crée un objet JSON et le stocke dans la table Pièce jointe \[sys_attachment\] avec une date d'expiration définie. Vous pouvez utiliser cette option pour créer des charges utiles de moins de 5 Mo.  

    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 utilise également l'API dans l'étape Script et crée la charge utile sous la forme d'une 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()
        .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()

      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"
    } ]
    }

## JSONStreamingAPI : close() {#ariaid-title2}

ferme l'objet JSONStreamingAPI. Doit appeler cette méthode pour fermer le flux après la génération d'un objet JSON.
{#JSA-close__table_izv_lb5_hlb__entry__3}

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

{#JSA-close__table_izv_lb5_hlb} {#JSA-close__table_jzv_lb5_hlb__entry__2}

| Type | Description |
|-|-|
| nul |   |
[Tableau 2. Renvoie]

{#JSA-close__table_jzv_lb5_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();
    }

## JSONStreamingAPI : disablePrettyPrint() {#ariaid-title3}

Met fin à un joli formatage JSON d'impression.
Avant d'appeler cette méthode, vous devez d'abord appeler enablePrettyPrint() pour ajouter un formatage JSON à une section spécifique.
{#JSA-disablePrettyPrint__table_ebl_hh2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 3. Paramètres]

{#JSA-disablePrettyPrint__table_ebl_hh2_1lb} {#JSA-disablePrettyPrint__table_fbl_hh2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 4. Renvoie]

{#JSA-disablePrettyPrint__table_fbl_hh2_1lb}  
Cet exemple ajoute une jolie mise en forme d'impression à l'objet `address` .

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

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")  
        .writeNumberField("age","25")
        .enablePrettyPrint()
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .disablePrettyPrint()
        .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"}]}

## JSONStreamingAPI : enablePrettyPrint() {#ariaid-title4}

Ajoute une jolie mise en forme d'impression à un objet JSON, ou à une section d'un objet JSON.
Pour désactiver la mise en forme des jolis caractères dans une section d'objets JSON, utilisez la méthode disablePrettyPrint().
{#JSA-enablePrettyPrint__table_h5h_gh2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 5. Paramètres]

{#JSA-enablePrettyPrint__table_h5h_gh2_1lb} {#JSA-enablePrettyPrint__table_fbl_hh2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 6. Renvoie]

{#JSA-enablePrettyPrint__table_fbl_hh2_1lb}  

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

      builder.enablePrettyPrint()
        .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"
    } ]
    }

## JSONStreamingAPI : endArray() {#ariaid-title5}

Ferme un tableau dans l'objet JSON parent.
Appelez d'abord la méthode startArray() pour ouvrir le tableau.
{#JSA-endArray__table_p1h_kf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 7. Paramètres]

{#JSA-endArray__table_p1h_kf2_1lb} {#JSA-endArray__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 8. Renvoie]

{#JSA-endArray__table_q1h_kf2_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();
    }

## JSONStreamingAPI : endObject() {#ariaid-title6}

Ferme un objet dans l'objet JSON parent.
Appelez d'abord la méthode startObject() pour ouvrir l'objet.
{#JSA-endObject__table_rzg_gf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 9. Paramètres]

{#JSA-endObject__table_rzg_gf2_1lb} {#JSA-endObject__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 10. Renvoie]

{#JSA-endObject__table_q1h_kf2_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();
    }

## JSONStreamingAPI : getAttachmentId() {#ariaid-title7}

Renvoie la sys_id de l'enregistrement de pièce jointe dans la table Pièces jointes de diffusion \[streaming_attachment\] qui contient la charge utile JSON.
Vous devez appeler la méthode withAttachment() dans la classe JSONStreamingBuilder pour enregistrer la charge utile JSON en tant que pièce jointe avant d'appeler cette méthode. Consultez [JSONStreamingBuilder - Dans le champ d'application](https://servicenow-prod.fluidtopics.net/Sqpv2xkEx0dYSQLZrtbmaA#JSONStreamingBuilderScopedAPI "Créez un objet de générateur utilisé pour générer 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 autre que la diffusion en continu.").
{#JSA-getAttachmentId__table_j2q_p25_hlb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 11. Paramètres]

{#JSA-getAttachmentId__table_j2q_p25_hlb} {#JSA-getAttachmentId__table_k2q_p25_hlb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Sys_id de l'enregistrement de pièce jointe dans la table Pièces jointes de diffusion \[streaming_attachment\] qui contient la charge utile JSON. |
[Tableau 12. Renvoie]

{#JSA-getAttachmentId__table_k2q_p25_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();
    }

## JSONStreamingAPI : getJSONString() {#ariaid-title8}

Renvoie l'objet JSON sous forme de chaîne.
Pour retourner l'objet JSON sous forme de chaîne, n'appelez pas la méthode withAttachment() dans la classe JSONStreamingBuilder . Consultez [JSONStreamingBuilder - Dans le champ d'application](https://servicenow-prod.fluidtopics.net/Sqpv2xkEx0dYSQLZrtbmaA#JSONStreamingBuilderScopedAPI "Créez un objet de générateur utilisé pour générer 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 autre que la diffusion en continu.").
{#JSA-getJSONString__table_bth_r25_hlb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 13. Paramètres]

{#JSA-getJSONString__table_bth_r25_hlb} {#JSA-getJSONString__table_cth_r25_hlb__entry__2}

| Type | Description |
|-|-|
| Chaîne | Contient l'objet JSON créé à l'aide de JSONStreamingAPI. |
[Tableau 14. Renvoie]

{#JSA-getJSONString__table_cth_r25_hlb}  

    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"
    } ]
    }

## JSONStreamingAPI : startArray() {#ariaid-title9}

Ouvre un tableau dans l'objet JSON parent.
Incluez la méthode endArray() pour fermer le tableau.
{#JSA-startArray__table_ljl_3f2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 15. Paramètres]

{#JSA-startArray__table_ljl_3f2_1lb} {#JSA-startArray__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 16. Renvoie]

{#JSA-startArray__table_q1h_kf2_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();
    }

## JSONStreamingAPI : startArrayField(String fieldName) {#ariaid-title10}

Crée un tableau dans l'objet JSON parent.
Entourez cette méthode des méthodes startArray() et endArray() pour ouvrir et fermer le tableau.
{#JSA-startArrayField_S__table_fmw_wg2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Fieldname | Chaîne | Nom du tableau. |
[Tableau 17. Paramètres]

{#JSA-startArrayField_S__table_fmw_wg2_1lb} {#JSA-startArrayField_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 18. Renvoie]

{#JSA-startArrayField_S__table_q1h_kf2_1lb}  

    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()
        .startArrayField("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();
    }

## JSONStreamingAPI : startObject() {#ariaid-title11}

Ouvre un objet dans l'objet JSON parent.
Nécessite la méthode endObject() pour fermer l'objet.
{#JSA-startObject__table_fmc_2f2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 19. Paramètres]

{#JSA-startObject__table_fmc_2f2_1lb} {#JSA-startObject__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 20. Renvoie]

{#JSA-startObject__table_q1h_kf2_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();
    }

## JSONStreamingAPI : writeBoolean(état booléen) {#ariaid-title12}

Ajoute une valeur booléenne à l'objet JSON parent.
{#JSA-writeBoolean_B__table_abc_4f2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| État | Booléen | Valeur booléenne à ajouter à l'objet JSON parent. Valeurs valides : * VRAI * faux {#JSA-writeBoolean_B__ul_js4_hzs_1mb} |
[Tableau 21. Paramètres]

{#JSA-writeBoolean_B__table_abc_4f2_1lb} {#JSA-writeBoolean_B__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 22. Renvoie]

{#JSA-writeBoolean_B__table_q1h_kf2_1lb}  

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

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeFieldName("activeUser")
        .writeBoolean(true)
        .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();
    }

## JSONStreamingAPI : writeBooleanField(String fieldName, valeur booléenne) {#ariaid-title13}

Ajoute un champ booléen et une valeur à l'objet JSON parent.
{#JSA-writeBooleanField_S_B__table_qtm_dh2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Fieldname | Chaîne | Nom du champ à ajouter à l'objet JSON parent. |
| valide | Booléen | Valeur booléenne à ajouter à l'objet JSON parent. Valeurs valides : * VRAI * faux {#JSA-writeBooleanField_S_B__ul_js4_hzs_1mb} |
[Tableau 23. Paramètres]

{#JSA-writeBooleanField_S_B__table_qtm_dh2_1lb} {#JSA-writeBooleanField_S_B__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 24. Renvoie]

{#JSA-writeBooleanField_S_B__table_q1h_kf2_1lb}  

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

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeBooleanField("activeUser", true)
        .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();
    }

## JSONStreamingAPI : writeFieldName(nom de la chaîne) {#ariaid-title14}

Ajoute un nom de champ à l'objet JSON parent.
{#JSA-writeFieldName_S__table_bsf_mf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| nom | Chaîne | Nom de champ à ajouter à l'objet JSON parent. |
[Tableau 25. Paramètres]

{#JSA-writeFieldName_S__table_bsf_mf2_1lb} {#JSA-writeFieldName_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 26. Renvoie]

{#JSA-writeFieldName_S__table_q1h_kf2_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();
    }

## JSONStreamingAPI : writeNull() {#ariaid-title15}

Ajoute une valeur null à l'objet JSON parent.
{#JSA-writeNull__table_bdp_wf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 27. Paramètres]

{#JSA-writeNull__table_bdp_wf2_1lb} {#JSA-writeNull__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 28. Renvoie]

{#JSA-writeNull__table_q1h_kf2_1lb}  

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

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeFieldName("activeUser")
        .writeNull()
        .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();
    }

## JSONStreamingAPI : writeNullField(String fieldName) {#ariaid-title16}

Ajoute un champ avec une valeur nulle à l'objet JSON parent.
{#JSA-writeNullField_S__table_ifs_nh2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Fieldname | Chaîne | Nom du champ nul. |
[Tableau 29. Paramètres]

{#JSA-writeNullField_S__table_ifs_nh2_1lb} {#JSA-writeNullField_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 30. Renvoie]

{#JSA-writeNullField_S__table_q1h_kf2_1lb}  

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

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNullField("activeUser")
        .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();
    }

## JSONStreamingAPI : writeNumberField(String, fieldName, String, encodedValue) {#ariaid-title17}

Ajoute un champ et une valeur numériques à l'objet JSON parent.
{#JSA-writeNumberField_S_S__table_bqd_rf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Fieldname | Chaîne | Nom du champ de numéro. |
| encodedValue | Chaîne | La valeur du champ de nombre. |
[Tableau 31. Paramètres]

{#JSA-writeNumberField_S_S__table_bqd_rf2_1lb} {#JSA-writeNumberField_S_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 32. Renvoie]

{#JSA-writeNumberField_S_S__table_q1h_kf2_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();
    }

## JSONStreamingAPI : writeRaw(texte de chaîne) {#ariaid-title18}

Ajoute une valeur brute à l'objet JSON parent.
{#JSA-writeRaw_S__table_pkv_5f2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Texte | Chaîne | Texte brut à ajouter à l'objet JSON parent. |
[Tableau 33. Paramètres]

{#JSA-writeRaw_S__table_pkv_5f2_1lb} {#JSA-writeRaw_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 34. Renvoie]

{#JSA-writeRaw_S__table_q1h_kf2_1lb}  

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

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeFieldName("filePath")
        .writeRaw("C:\Users\profile\aboutme.html")
        .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();
    }

## JSONStreamingAPI : writeString(String texte) {#ariaid-title19}

Ajoute une valeur de chaîne à l'objet JSON parent.
{#JSA-writeString_S__table_arf_tf2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Texte | Chaîne | Valeur de chaîne à ajouter à l'objet JSON parent. |
[Tableau 35. Paramètres]

{#JSA-writeString_S__table_arf_tf2_1lb} {#JSA-writeString_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 36. Renvoie]

{#JSA-writeString_S__table_q1h_kf2_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();
    }

## JSONStreamingAPI : writeStringField(String fieldName, valeur de chaîne) {#ariaid-title20}

Ajoute un champ et une valeur de chaîne à l'objet JSON parent.
{#JSA-writeStringField_S_S__table_qtm_dh2_1lb__entry__3}

| Nom | Type | Description |
|-|-|-|
| Fieldname | Chaîne | Nom du champ à ajouter à l'objet JSON parent. |
| valide | Chaîne | La valeur du champ. |
[Tableau 37. Paramètres]

{#JSA-writeStringField_S_S__table_qtm_dh2_1lb} {#JSA-writeStringField_S_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| API JSONStreamingAPI | Objet JSON de diffusion en continu utilisé pour construire la charge utile. |
[Tableau 38. Renvoie]

{#JSA-writeStringField_S_S__table_q1h_kf2_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();
    }


