what is the fundamental difference between jsonlite and rjson packages?












2















The rjson::fromJSON() reads a file incorrectly while jsonlite::fromJSON() reads it fine. Here's a sample example.



file test.json contents:



{"name": "Sanjay",
"unit_price": 130848,
"amount": 11,
"up_to_data_sales": 45725}


the jsonlite fromJSON outputs:



jsonlite::fromJSON("test.json")
$name
[1] "Sanjay"

$unit_price
[1] 130848

$amount
[1] 11

$up_to_data_sales
[1] 45725


But the same throws an error in rjson package.



rjson::fromJSON("test.json") 

Error in rjson::fromJSON("test.json") : parseTrue: expected to see 'true' - likely an unquoted string starting with 't'.



  1. Why is this error coming?

  2. What is the reason rjson package was launched when jsonlite existed?










share|improve this question



























    2















    The rjson::fromJSON() reads a file incorrectly while jsonlite::fromJSON() reads it fine. Here's a sample example.



    file test.json contents:



    {"name": "Sanjay",
    "unit_price": 130848,
    "amount": 11,
    "up_to_data_sales": 45725}


    the jsonlite fromJSON outputs:



    jsonlite::fromJSON("test.json")
    $name
    [1] "Sanjay"

    $unit_price
    [1] 130848

    $amount
    [1] 11

    $up_to_data_sales
    [1] 45725


    But the same throws an error in rjson package.



    rjson::fromJSON("test.json") 

    Error in rjson::fromJSON("test.json") : parseTrue: expected to see 'true' - likely an unquoted string starting with 't'.



    1. Why is this error coming?

    2. What is the reason rjson package was launched when jsonlite existed?










    share|improve this question

























      2












      2








      2








      The rjson::fromJSON() reads a file incorrectly while jsonlite::fromJSON() reads it fine. Here's a sample example.



      file test.json contents:



      {"name": "Sanjay",
      "unit_price": 130848,
      "amount": 11,
      "up_to_data_sales": 45725}


      the jsonlite fromJSON outputs:



      jsonlite::fromJSON("test.json")
      $name
      [1] "Sanjay"

      $unit_price
      [1] 130848

      $amount
      [1] 11

      $up_to_data_sales
      [1] 45725


      But the same throws an error in rjson package.



      rjson::fromJSON("test.json") 

      Error in rjson::fromJSON("test.json") : parseTrue: expected to see 'true' - likely an unquoted string starting with 't'.



      1. Why is this error coming?

      2. What is the reason rjson package was launched when jsonlite existed?










      share|improve this question














      The rjson::fromJSON() reads a file incorrectly while jsonlite::fromJSON() reads it fine. Here's a sample example.



      file test.json contents:



      {"name": "Sanjay",
      "unit_price": 130848,
      "amount": 11,
      "up_to_data_sales": 45725}


      the jsonlite fromJSON outputs:



      jsonlite::fromJSON("test.json")
      $name
      [1] "Sanjay"

      $unit_price
      [1] 130848

      $amount
      [1] 11

      $up_to_data_sales
      [1] 45725


      But the same throws an error in rjson package.



      rjson::fromJSON("test.json") 

      Error in rjson::fromJSON("test.json") : parseTrue: expected to see 'true' - likely an unquoted string starting with 't'.



      1. Why is this error coming?

      2. What is the reason rjson package was launched when jsonlite existed?







      r json






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 17:36









      Dhruv MehrotraDhruv Mehrotra

      132




      132
























          2 Answers
          2






          active

          oldest

          votes


















          2














          Well:



          stringdist::stringdist("rjson", "jsonlite")
          ## [1] 5


          That's a modest difference to begin with.



          However, your assertion seems to be amiss:



          library(magrittr)

          rjson::fromJSON('{"name": "Sanjay",
          "unit_price": 130848,
          "amount": 11,
          "up_to_data_sales": 45725}') %>% str()
          ## List of 4
          ## $ name : chr "Sanjay"
          ## $ unit_price : num 130848
          ## $ amount : num 11
          ## $ up_to_data_sales: num 45725

          jsonlite::fromJSON('{"name": "Sanjay",
          "unit_price": 130848,
          "amount": 11,
          "up_to_data_sales": 45725}') %>% str()
          ## List of 4
          ## $ name : chr "Sanjay"
          ## $ unit_price : int 130848
          ## $ amount : int 11
          ## $ up_to_data_sales: int 45725


          Apart from jsonlite using a more diminutive data type for the numbers, they both parse the JSON fine.



          So there's an issue with your file that you failed to disclose in the question.



          A further incorrect assertion



          -rw-rw-r--  1 bob  staff      2690 Jul 30  2007 rjson_0.1.0.tar.gz
          -rw-rw-r-- 1 bob staff 400196 Dec 3 2013 jsonlite_0.9.0.tar.gz


          not to mention:



          -rw-rw-r--  1 bob   staff   873843 Oct  4  2010 RJSONIO_0.3-1.tar.gz


          rjson came first. (dir listings came from the CRAN mirror sitting next to me).



          You can actually read about the rationale and impetus behind jsonlite here: https://arxiv.org/abs/1403.2805 (which I got off the CRAN page for jsonlite.






          share|improve this answer

































            0














            This is an answer for the question asked but not for the example



            There is a difference in the way they read files:



            For example consider the following input:



            {
            "id": 1,
            "prod_info": [
            {
            "product": "xyz",
            "brand": "pqr",
            "price": 500
            },
            {
            "product": "abc",
            "brand": "klm",
            "price": 5000
            }
            ]
            }



            prod_info in the above input is a list with 2 vectors. But jsonlite reads it in the form of dataframe while rjson reads it as a list



            x <- jsonlite::fromJSON("input.json")
            y <- rjson::fromJSON(file = "Input.json") #rjson does not read the file if 'file=' command is not given


            Outputs:



            x
            $id
            [1] 1

            $prod_info
            product brand price
            1 xyz pqr 500
            2 abc klm 5000

            y
            $id
            [1] 1

            $prod_info
            $prod_info[[1]]
            $prod_info[[1]]$product
            [1] "xyz"

            $prod_info[[1]]$brand
            [1] "pqr"

            $prod_info[[1]]$price
            [1] 500


            $prod_info[[2]]
            $prod_info[[2]]$product
            [1] "abc"

            $prod_info[[2]]$brand
            [1] "klm"

            $prod_info[[2]]$price
            [1] 5000

            class(x$prod_info)
            [1] "data.frame"

            class(y$prod_info)
            [1] "list"





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2fstackoverflow.com%2fquestions%2f53379940%2fwhat-is-the-fundamental-difference-between-jsonlite-and-rjson-packages%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              Well:



              stringdist::stringdist("rjson", "jsonlite")
              ## [1] 5


              That's a modest difference to begin with.



              However, your assertion seems to be amiss:



              library(magrittr)

              rjson::fromJSON('{"name": "Sanjay",
              "unit_price": 130848,
              "amount": 11,
              "up_to_data_sales": 45725}') %>% str()
              ## List of 4
              ## $ name : chr "Sanjay"
              ## $ unit_price : num 130848
              ## $ amount : num 11
              ## $ up_to_data_sales: num 45725

              jsonlite::fromJSON('{"name": "Sanjay",
              "unit_price": 130848,
              "amount": 11,
              "up_to_data_sales": 45725}') %>% str()
              ## List of 4
              ## $ name : chr "Sanjay"
              ## $ unit_price : int 130848
              ## $ amount : int 11
              ## $ up_to_data_sales: int 45725


              Apart from jsonlite using a more diminutive data type for the numbers, they both parse the JSON fine.



              So there's an issue with your file that you failed to disclose in the question.



              A further incorrect assertion



              -rw-rw-r--  1 bob  staff      2690 Jul 30  2007 rjson_0.1.0.tar.gz
              -rw-rw-r-- 1 bob staff 400196 Dec 3 2013 jsonlite_0.9.0.tar.gz


              not to mention:



              -rw-rw-r--  1 bob   staff   873843 Oct  4  2010 RJSONIO_0.3-1.tar.gz


              rjson came first. (dir listings came from the CRAN mirror sitting next to me).



              You can actually read about the rationale and impetus behind jsonlite here: https://arxiv.org/abs/1403.2805 (which I got off the CRAN page for jsonlite.






              share|improve this answer






























                2














                Well:



                stringdist::stringdist("rjson", "jsonlite")
                ## [1] 5


                That's a modest difference to begin with.



                However, your assertion seems to be amiss:



                library(magrittr)

                rjson::fromJSON('{"name": "Sanjay",
                "unit_price": 130848,
                "amount": 11,
                "up_to_data_sales": 45725}') %>% str()
                ## List of 4
                ## $ name : chr "Sanjay"
                ## $ unit_price : num 130848
                ## $ amount : num 11
                ## $ up_to_data_sales: num 45725

                jsonlite::fromJSON('{"name": "Sanjay",
                "unit_price": 130848,
                "amount": 11,
                "up_to_data_sales": 45725}') %>% str()
                ## List of 4
                ## $ name : chr "Sanjay"
                ## $ unit_price : int 130848
                ## $ amount : int 11
                ## $ up_to_data_sales: int 45725


                Apart from jsonlite using a more diminutive data type for the numbers, they both parse the JSON fine.



                So there's an issue with your file that you failed to disclose in the question.



                A further incorrect assertion



                -rw-rw-r--  1 bob  staff      2690 Jul 30  2007 rjson_0.1.0.tar.gz
                -rw-rw-r-- 1 bob staff 400196 Dec 3 2013 jsonlite_0.9.0.tar.gz


                not to mention:



                -rw-rw-r--  1 bob   staff   873843 Oct  4  2010 RJSONIO_0.3-1.tar.gz


                rjson came first. (dir listings came from the CRAN mirror sitting next to me).



                You can actually read about the rationale and impetus behind jsonlite here: https://arxiv.org/abs/1403.2805 (which I got off the CRAN page for jsonlite.






                share|improve this answer




























                  2












                  2








                  2







                  Well:



                  stringdist::stringdist("rjson", "jsonlite")
                  ## [1] 5


                  That's a modest difference to begin with.



                  However, your assertion seems to be amiss:



                  library(magrittr)

                  rjson::fromJSON('{"name": "Sanjay",
                  "unit_price": 130848,
                  "amount": 11,
                  "up_to_data_sales": 45725}') %>% str()
                  ## List of 4
                  ## $ name : chr "Sanjay"
                  ## $ unit_price : num 130848
                  ## $ amount : num 11
                  ## $ up_to_data_sales: num 45725

                  jsonlite::fromJSON('{"name": "Sanjay",
                  "unit_price": 130848,
                  "amount": 11,
                  "up_to_data_sales": 45725}') %>% str()
                  ## List of 4
                  ## $ name : chr "Sanjay"
                  ## $ unit_price : int 130848
                  ## $ amount : int 11
                  ## $ up_to_data_sales: int 45725


                  Apart from jsonlite using a more diminutive data type for the numbers, they both parse the JSON fine.



                  So there's an issue with your file that you failed to disclose in the question.



                  A further incorrect assertion



                  -rw-rw-r--  1 bob  staff      2690 Jul 30  2007 rjson_0.1.0.tar.gz
                  -rw-rw-r-- 1 bob staff 400196 Dec 3 2013 jsonlite_0.9.0.tar.gz


                  not to mention:



                  -rw-rw-r--  1 bob   staff   873843 Oct  4  2010 RJSONIO_0.3-1.tar.gz


                  rjson came first. (dir listings came from the CRAN mirror sitting next to me).



                  You can actually read about the rationale and impetus behind jsonlite here: https://arxiv.org/abs/1403.2805 (which I got off the CRAN page for jsonlite.






                  share|improve this answer















                  Well:



                  stringdist::stringdist("rjson", "jsonlite")
                  ## [1] 5


                  That's a modest difference to begin with.



                  However, your assertion seems to be amiss:



                  library(magrittr)

                  rjson::fromJSON('{"name": "Sanjay",
                  "unit_price": 130848,
                  "amount": 11,
                  "up_to_data_sales": 45725}') %>% str()
                  ## List of 4
                  ## $ name : chr "Sanjay"
                  ## $ unit_price : num 130848
                  ## $ amount : num 11
                  ## $ up_to_data_sales: num 45725

                  jsonlite::fromJSON('{"name": "Sanjay",
                  "unit_price": 130848,
                  "amount": 11,
                  "up_to_data_sales": 45725}') %>% str()
                  ## List of 4
                  ## $ name : chr "Sanjay"
                  ## $ unit_price : int 130848
                  ## $ amount : int 11
                  ## $ up_to_data_sales: int 45725


                  Apart from jsonlite using a more diminutive data type for the numbers, they both parse the JSON fine.



                  So there's an issue with your file that you failed to disclose in the question.



                  A further incorrect assertion



                  -rw-rw-r--  1 bob  staff      2690 Jul 30  2007 rjson_0.1.0.tar.gz
                  -rw-rw-r-- 1 bob staff 400196 Dec 3 2013 jsonlite_0.9.0.tar.gz


                  not to mention:



                  -rw-rw-r--  1 bob   staff   873843 Oct  4  2010 RJSONIO_0.3-1.tar.gz


                  rjson came first. (dir listings came from the CRAN mirror sitting next to me).



                  You can actually read about the rationale and impetus behind jsonlite here: https://arxiv.org/abs/1403.2805 (which I got off the CRAN page for jsonlite.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 '18 at 18:50

























                  answered Nov 19 '18 at 18:16









                  hrbrmstrhrbrmstr

                  61.1k690151




                  61.1k690151

























                      0














                      This is an answer for the question asked but not for the example



                      There is a difference in the way they read files:



                      For example consider the following input:



                      {
                      "id": 1,
                      "prod_info": [
                      {
                      "product": "xyz",
                      "brand": "pqr",
                      "price": 500
                      },
                      {
                      "product": "abc",
                      "brand": "klm",
                      "price": 5000
                      }
                      ]
                      }



                      prod_info in the above input is a list with 2 vectors. But jsonlite reads it in the form of dataframe while rjson reads it as a list



                      x <- jsonlite::fromJSON("input.json")
                      y <- rjson::fromJSON(file = "Input.json") #rjson does not read the file if 'file=' command is not given


                      Outputs:



                      x
                      $id
                      [1] 1

                      $prod_info
                      product brand price
                      1 xyz pqr 500
                      2 abc klm 5000

                      y
                      $id
                      [1] 1

                      $prod_info
                      $prod_info[[1]]
                      $prod_info[[1]]$product
                      [1] "xyz"

                      $prod_info[[1]]$brand
                      [1] "pqr"

                      $prod_info[[1]]$price
                      [1] 500


                      $prod_info[[2]]
                      $prod_info[[2]]$product
                      [1] "abc"

                      $prod_info[[2]]$brand
                      [1] "klm"

                      $prod_info[[2]]$price
                      [1] 5000

                      class(x$prod_info)
                      [1] "data.frame"

                      class(y$prod_info)
                      [1] "list"





                      share|improve this answer




























                        0














                        This is an answer for the question asked but not for the example



                        There is a difference in the way they read files:



                        For example consider the following input:



                        {
                        "id": 1,
                        "prod_info": [
                        {
                        "product": "xyz",
                        "brand": "pqr",
                        "price": 500
                        },
                        {
                        "product": "abc",
                        "brand": "klm",
                        "price": 5000
                        }
                        ]
                        }



                        prod_info in the above input is a list with 2 vectors. But jsonlite reads it in the form of dataframe while rjson reads it as a list



                        x <- jsonlite::fromJSON("input.json")
                        y <- rjson::fromJSON(file = "Input.json") #rjson does not read the file if 'file=' command is not given


                        Outputs:



                        x
                        $id
                        [1] 1

                        $prod_info
                        product brand price
                        1 xyz pqr 500
                        2 abc klm 5000

                        y
                        $id
                        [1] 1

                        $prod_info
                        $prod_info[[1]]
                        $prod_info[[1]]$product
                        [1] "xyz"

                        $prod_info[[1]]$brand
                        [1] "pqr"

                        $prod_info[[1]]$price
                        [1] 500


                        $prod_info[[2]]
                        $prod_info[[2]]$product
                        [1] "abc"

                        $prod_info[[2]]$brand
                        [1] "klm"

                        $prod_info[[2]]$price
                        [1] 5000

                        class(x$prod_info)
                        [1] "data.frame"

                        class(y$prod_info)
                        [1] "list"





                        share|improve this answer


























                          0












                          0








                          0







                          This is an answer for the question asked but not for the example



                          There is a difference in the way they read files:



                          For example consider the following input:



                          {
                          "id": 1,
                          "prod_info": [
                          {
                          "product": "xyz",
                          "brand": "pqr",
                          "price": 500
                          },
                          {
                          "product": "abc",
                          "brand": "klm",
                          "price": 5000
                          }
                          ]
                          }



                          prod_info in the above input is a list with 2 vectors. But jsonlite reads it in the form of dataframe while rjson reads it as a list



                          x <- jsonlite::fromJSON("input.json")
                          y <- rjson::fromJSON(file = "Input.json") #rjson does not read the file if 'file=' command is not given


                          Outputs:



                          x
                          $id
                          [1] 1

                          $prod_info
                          product brand price
                          1 xyz pqr 500
                          2 abc klm 5000

                          y
                          $id
                          [1] 1

                          $prod_info
                          $prod_info[[1]]
                          $prod_info[[1]]$product
                          [1] "xyz"

                          $prod_info[[1]]$brand
                          [1] "pqr"

                          $prod_info[[1]]$price
                          [1] 500


                          $prod_info[[2]]
                          $prod_info[[2]]$product
                          [1] "abc"

                          $prod_info[[2]]$brand
                          [1] "klm"

                          $prod_info[[2]]$price
                          [1] 5000

                          class(x$prod_info)
                          [1] "data.frame"

                          class(y$prod_info)
                          [1] "list"





                          share|improve this answer













                          This is an answer for the question asked but not for the example



                          There is a difference in the way they read files:



                          For example consider the following input:



                          {
                          "id": 1,
                          "prod_info": [
                          {
                          "product": "xyz",
                          "brand": "pqr",
                          "price": 500
                          },
                          {
                          "product": "abc",
                          "brand": "klm",
                          "price": 5000
                          }
                          ]
                          }



                          prod_info in the above input is a list with 2 vectors. But jsonlite reads it in the form of dataframe while rjson reads it as a list



                          x <- jsonlite::fromJSON("input.json")
                          y <- rjson::fromJSON(file = "Input.json") #rjson does not read the file if 'file=' command is not given


                          Outputs:



                          x
                          $id
                          [1] 1

                          $prod_info
                          product brand price
                          1 xyz pqr 500
                          2 abc klm 5000

                          y
                          $id
                          [1] 1

                          $prod_info
                          $prod_info[[1]]
                          $prod_info[[1]]$product
                          [1] "xyz"

                          $prod_info[[1]]$brand
                          [1] "pqr"

                          $prod_info[[1]]$price
                          [1] 500


                          $prod_info[[2]]
                          $prod_info[[2]]$product
                          [1] "abc"

                          $prod_info[[2]]$brand
                          [1] "klm"

                          $prod_info[[2]]$price
                          [1] 5000

                          class(x$prod_info)
                          [1] "data.frame"

                          class(y$prod_info)
                          [1] "list"






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 3 at 6:58









                          Hinduja ElluruHinduja Elluru

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • 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%2fstackoverflow.com%2fquestions%2f53379940%2fwhat-is-the-fundamental-difference-between-jsonlite-and-rjson-packages%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







                              這個網誌中的熱門文章

                              Xamarin.form Move up view when keyboard appear

                              Post-Redirect-Get with Spring WebFlux and Thymeleaf

                              Anylogic : not able to use stopDelay()