How do I use JSON.generator to generate an unnamed array?How do I generate a random string?Scheduled Apex Class Testing IssueJson Generator Object within ArraySystem.JSONException: Unexpected character ('}' (code 125))How to deserialize JSON to sObject?JSONError - System.JSONException: Can not start an object, expecting field nameAPEX Deserializing/Parsing RESTful JSON Webservice ResponseHow to grab everything between start of substring and and of text?Apex Quick Start — How do I use the Book?JSON generation in apex batch - how to correctly configure cc in email sending

2 weeks and a tight budget to prepare for Z-day. How long can I hunker down?

Is it okay for me to decline a project on ethical grounds?

8086 stack segment and avoiding overflow in interrupts

Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?

What is this 4 sharp symbol and what does it mean?

Does a 401(k) loan count as debt when calculating Debt-to-Income Ratio?

Is there a way to know the composition of a Team GO Rocket before going into the fight?

Why did House of Representatives need to condemn Trumps Tweets?

How can I say in Russian "I am not afraid to write anything"?

Copying an existing HTML page and use it, is that against any copyright law?

Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?

Can you place a support header in the ceiling?

Compound Word Neologism

If Trump gets impeached, how long would Pence be president?

Why is the number of local variables used in a Java bytecode method not the most economical?

Telling manager project isn't worth the effort?

ECDSA: Why is SigningKey shorter than VerifyingKey

(3 of 11: Akari) What is Pyramid Cult's Favorite Car?

Desktop app status bar: Notification vs error message

Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?

How long until two planets become one?

Introducing Tetronogram!

Are there any unpublished Iain M. Banks short stories?

What do I do with a party that is much stronger than their level?



How do I use JSON.generator to generate an unnamed array?


How do I generate a random string?Scheduled Apex Class Testing IssueJson Generator Object within ArraySystem.JSONException: Unexpected character ('}' (code 125))How to deserialize JSON to sObject?JSONError - System.JSONException: Can not start an object, expecting field nameAPEX Deserializing/Parsing RESTful JSON Webservice ResponseHow to grab everything between start of substring and and of text?Apex Quick Start — How do I use the Book?JSON generation in apex batch - how to correctly configure cc in email sending






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I'm trying to generate:




"["hello" : "world"]"




gen.writeStartObject();
gen.writeArrayStart();
gen.writeStartObject();
gen.writeStringFeild('hello', 'world');
gen.writeEndObject();
gen.writeArrayEnd();
gen.writeEndObject();


Throws the error:
System.JSONException: Can not start an array, expecting field name



But the array in my example does not have a field name?










share|improve this question






























    2















    I'm trying to generate:




    "["hello" : "world"]"




    gen.writeStartObject();
    gen.writeArrayStart();
    gen.writeStartObject();
    gen.writeStringFeild('hello', 'world');
    gen.writeEndObject();
    gen.writeArrayEnd();
    gen.writeEndObject();


    Throws the error:
    System.JSONException: Can not start an array, expecting field name



    But the array in my example does not have a field name?










    share|improve this question


























      2












      2








      2








      I'm trying to generate:




      "["hello" : "world"]"




      gen.writeStartObject();
      gen.writeArrayStart();
      gen.writeStartObject();
      gen.writeStringFeild('hello', 'world');
      gen.writeEndObject();
      gen.writeArrayEnd();
      gen.writeEndObject();


      Throws the error:
      System.JSONException: Can not start an array, expecting field name



      But the array in my example does not have a field name?










      share|improve this question














      I'm trying to generate:




      "["hello" : "world"]"




      gen.writeStartObject();
      gen.writeArrayStart();
      gen.writeStartObject();
      gen.writeStringFeild('hello', 'world');
      gen.writeEndObject();
      gen.writeArrayEnd();
      gen.writeEndObject();


      Throws the error:
      System.JSONException: Can not start an array, expecting field name



      But the array in my example does not have a field name?







      apex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      muchaviemuchavie

      763 bronze badges




      763 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          5














          Right now, you open an object before opening your array. An object must consist of field value pairs. Here is an annotated version of what you wrote above, with your three typos corrected.



          gen.writeStartObject();
          // output:
          // remove this line

          gen.writeStartArray();
          // output: [
          // your post had a typo here which I have fixed
          // using writeStartArray rather than writeArrayStart

          gen.writeStartObject();
          // output:

          gen.writeStringField('hello', 'world');
          // output: "hello": "world"
          // your post had a typo here which I have fixed
          // using writeStringField rather than writeStringFeild

          gen.writeEndObject();
          // output:

          gen.writeEndArray();
          // output: ]
          // your post had a typo here which I have fixed
          // using writeEndArray rather than writeArrayEnd

          gen.writeEndObject();
          // output:
          // remove this line


          Please note that JSONGenerator is almost never the correct choice for the job. It is almost universally simpler, easier to read, and better performance to just use out of the box serialization/deserialization. For example, here you could write just one line:



          String payload = JSON.serialize(new List<Object> 
          new Map<String, String> 'hello' => 'world'
          );





          share|improve this answer






















          • 1





            Also its writeStartArray and writeEndArray

            – salesforcesas
            8 hours ago











          • Thank you Adrian!

            – muchavie
            8 hours ago






          • 1





            @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

            – Adrian Larson
            8 hours ago













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f271469%2fhow-do-i-use-json-generator-to-generate-an-unnamed-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          Right now, you open an object before opening your array. An object must consist of field value pairs. Here is an annotated version of what you wrote above, with your three typos corrected.



          gen.writeStartObject();
          // output:
          // remove this line

          gen.writeStartArray();
          // output: [
          // your post had a typo here which I have fixed
          // using writeStartArray rather than writeArrayStart

          gen.writeStartObject();
          // output:

          gen.writeStringField('hello', 'world');
          // output: "hello": "world"
          // your post had a typo here which I have fixed
          // using writeStringField rather than writeStringFeild

          gen.writeEndObject();
          // output:

          gen.writeEndArray();
          // output: ]
          // your post had a typo here which I have fixed
          // using writeEndArray rather than writeArrayEnd

          gen.writeEndObject();
          // output:
          // remove this line


          Please note that JSONGenerator is almost never the correct choice for the job. It is almost universally simpler, easier to read, and better performance to just use out of the box serialization/deserialization. For example, here you could write just one line:



          String payload = JSON.serialize(new List<Object> 
          new Map<String, String> 'hello' => 'world'
          );





          share|improve this answer






















          • 1





            Also its writeStartArray and writeEndArray

            – salesforcesas
            8 hours ago











          • Thank you Adrian!

            – muchavie
            8 hours ago






          • 1





            @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

            – Adrian Larson
            8 hours ago















          5














          Right now, you open an object before opening your array. An object must consist of field value pairs. Here is an annotated version of what you wrote above, with your three typos corrected.



          gen.writeStartObject();
          // output:
          // remove this line

          gen.writeStartArray();
          // output: [
          // your post had a typo here which I have fixed
          // using writeStartArray rather than writeArrayStart

          gen.writeStartObject();
          // output:

          gen.writeStringField('hello', 'world');
          // output: "hello": "world"
          // your post had a typo here which I have fixed
          // using writeStringField rather than writeStringFeild

          gen.writeEndObject();
          // output:

          gen.writeEndArray();
          // output: ]
          // your post had a typo here which I have fixed
          // using writeEndArray rather than writeArrayEnd

          gen.writeEndObject();
          // output:
          // remove this line


          Please note that JSONGenerator is almost never the correct choice for the job. It is almost universally simpler, easier to read, and better performance to just use out of the box serialization/deserialization. For example, here you could write just one line:



          String payload = JSON.serialize(new List<Object> 
          new Map<String, String> 'hello' => 'world'
          );





          share|improve this answer






















          • 1





            Also its writeStartArray and writeEndArray

            – salesforcesas
            8 hours ago











          • Thank you Adrian!

            – muchavie
            8 hours ago






          • 1





            @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

            – Adrian Larson
            8 hours ago













          5












          5








          5







          Right now, you open an object before opening your array. An object must consist of field value pairs. Here is an annotated version of what you wrote above, with your three typos corrected.



          gen.writeStartObject();
          // output:
          // remove this line

          gen.writeStartArray();
          // output: [
          // your post had a typo here which I have fixed
          // using writeStartArray rather than writeArrayStart

          gen.writeStartObject();
          // output:

          gen.writeStringField('hello', 'world');
          // output: "hello": "world"
          // your post had a typo here which I have fixed
          // using writeStringField rather than writeStringFeild

          gen.writeEndObject();
          // output:

          gen.writeEndArray();
          // output: ]
          // your post had a typo here which I have fixed
          // using writeEndArray rather than writeArrayEnd

          gen.writeEndObject();
          // output:
          // remove this line


          Please note that JSONGenerator is almost never the correct choice for the job. It is almost universally simpler, easier to read, and better performance to just use out of the box serialization/deserialization. For example, here you could write just one line:



          String payload = JSON.serialize(new List<Object> 
          new Map<String, String> 'hello' => 'world'
          );





          share|improve this answer















          Right now, you open an object before opening your array. An object must consist of field value pairs. Here is an annotated version of what you wrote above, with your three typos corrected.



          gen.writeStartObject();
          // output:
          // remove this line

          gen.writeStartArray();
          // output: [
          // your post had a typo here which I have fixed
          // using writeStartArray rather than writeArrayStart

          gen.writeStartObject();
          // output:

          gen.writeStringField('hello', 'world');
          // output: "hello": "world"
          // your post had a typo here which I have fixed
          // using writeStringField rather than writeStringFeild

          gen.writeEndObject();
          // output:

          gen.writeEndArray();
          // output: ]
          // your post had a typo here which I have fixed
          // using writeEndArray rather than writeArrayEnd

          gen.writeEndObject();
          // output:
          // remove this line


          Please note that JSONGenerator is almost never the correct choice for the job. It is almost universally simpler, easier to read, and better performance to just use out of the box serialization/deserialization. For example, here you could write just one line:



          String payload = JSON.serialize(new List<Object> 
          new Map<String, String> 'hello' => 'world'
          );






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago

























          answered 9 hours ago









          Adrian LarsonAdrian Larson

          115k19 gold badges133 silver badges272 bronze badges




          115k19 gold badges133 silver badges272 bronze badges










          • 1





            Also its writeStartArray and writeEndArray

            – salesforcesas
            8 hours ago











          • Thank you Adrian!

            – muchavie
            8 hours ago






          • 1





            @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

            – Adrian Larson
            8 hours ago












          • 1





            Also its writeStartArray and writeEndArray

            – salesforcesas
            8 hours ago











          • Thank you Adrian!

            – muchavie
            8 hours ago






          • 1





            @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

            – Adrian Larson
            8 hours ago







          1




          1





          Also its writeStartArray and writeEndArray

          – salesforcesas
          8 hours ago





          Also its writeStartArray and writeEndArray

          – salesforcesas
          8 hours ago













          Thank you Adrian!

          – muchavie
          8 hours ago





          Thank you Adrian!

          – muchavie
          8 hours ago




          1




          1





          @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

          – Adrian Larson
          8 hours ago





          @muchavie If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.

          – Adrian Larson
          8 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f271469%2fhow-do-i-use-json-generator-to-generate-an-unnamed-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單