Menu

#745 Support for JSON

v1.25
closed-fixed
nobody
5
2015-07-23
2014-11-23
beatboxa
No

Feature request for support of JSON data (including condensed JSON). May be able to port quickly from YAML.

Here is a valid condensed JSON record that does not appear to parse correctly in Geany 1.23.1 on Ubuntu 14.04:
{"foo": "bar","baz": ["qux","quxx"],"corge": null,"grault":1,"garply": true,"waldo": "false","fred":"undefined","emptyArray": [],"emptyObject": {},"emptyString": ""}

I've followed the wiki here (including the both the YAML lexer and the Javascript lexer):
http://wiki.geany.org/config/json

But this does not appear to parse JSON properly, particularly when condensed--possibly due to slightly different parsing between YAML and JSON.

For the purposes of sample data for testing and comparing, these sites may be useful:
http://jsontoyaml.com/
http://yamltojson.com/

Thanks in advance; and please let me know how I can contribute to this effort!

Related

Feature Requests: #745

Discussion

  • Colomban Wendling

    What do you mean by "does not appear to parse correctly in Geany 1.23.1"?
    If I put this snippet in Geany (from Git, latest dev version) and set the filetype to JavaScript it highlight and folds just fine (which is expeced as IIUC JSON is a strict subset of JavaScript grammar).

    But no, it doesn't generate a symbol list (nor does it for YAML data BTW). This could be fixed by writing a CTags parser for JSON (and to my basic understanding of the format I believe it should be pretty trivial), but this also means adding a builtin filetype to Geany, so a little more work.

     
  • Colomban Wendling

    I fixed the wiki page to propose a working filetype file

     
  • beatboxa

    beatboxa - 2014-11-27

    Thanks for the update here and in the wiki!

    Using JavaScript as the filetype doesn't appear to identify the arrays properly. For example, if you go to the jsontoyaml.com site I listed, convert the default JSON example to YAML, and paste the YAML into Geany, Geany correctly identifies an array called 'baz' (which you can hide or expand with the "+" button.

    Pasting in the equivalent JSON and selecting javascript doesn't appear to identify 'baz' as an array that can be expanded. Only the outermost '{}' brackets are recognized as containing an array.

     
    • Lex Trotman

      Lex Trotman - 2014-11-27

      Javascript doesn't fold on arrays, only on {} since that is the block
      construct in Javascript, but since JSON is Javascript it highlights
      properly.

      YAML folds on both {} and [] (at least in the example you linked to)
      but doesn't highlight since JSON isn't YAML.

      Cheers
      Lex

      On 27 November 2014 at 13:26, arslaan beatboxa@users.sf.net wrote:

      Thanks for the update here and in the wiki!

      Using JavaScript as the filetype doesn't appear to identify the arrays
      properly. For example, if you go to the jsontoyaml.com site I listed,
      convert the default JSON example to YAML, and paste the YAML into Geany,
      Geany correctly identifies an array called 'baz' (which you can hide or
      expand with the "+" button.

      Pasting in the equivalent JSON and selecting javascript doesn't appear to
      identify 'baz' as an array that can be expanded. Only the outermost '{}'
      brackets are recognized as containing an array.


      [feature-requests:#745] Support for JSON

      Status: open
      Group: v1.25
      Labels: filetype json yaml filedefs
      Created: Sun Nov 23, 2014 06:15 PM UTC by arslaan
      Last Updated: Thu Nov 27, 2014 12:48 AM UTC
      Owner: nobody

      Feature request for support of JSON data (including condensed JSON). May be
      able to port quickly from YAML.

      Here is a valid condensed JSON record that does not appear to parse
      correctly in Geany 1.23.1 on Ubuntu 14.04:
      {"foo": "bar","baz": ["qux","quxx"],"corge": null,"grault":1,"garply":
      true,"waldo": "false","fred":"undefined","emptyArray": [],"emptyObject":
      {},"emptyString": ""}

      I've followed the wiki here (including the both the YAML lexer and the
      Javascript lexer):
      http://wiki.geany.org/config/json

      But this does not appear to parse JSON properly, particularly when
      condensed--possibly due to slightly different parsing between YAML and JSON.

      For the purposes of sample data for testing and comparing, these sites may
      be useful:
      http://jsontoyaml.com/
      http://yamltojson.com/

      Thanks in advance; and please let me know how I can contribute to this
      effort!


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/geany/feature-requests/745/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Feature Requests: #745

      • Colomban Wendling

        YAML folds on both {} and [] (at least in the example you linked to) […]

        Actually YAML folds on indentation only, so if it did with this example is only because it was indented like YAML requires.

         
      • beatboxa

        beatboxa - 2014-11-27

        Correct, but what I am asking for is support for JSON specifically, not Javascript in general (which already appears to work fine). So a JSON file should fold appropriately, since JSON is not 100% the same as Javascript.

        Actually, I guess the ask would be 'folding on arrays in the condensed version of any markup language' if YAML also does not fold in condensed version.

        Today, I use a browser extension to browse and alter JSON's (including condensed version JSON with nested arrays). This extension can fold and unfold arrays and makes it very easy to explore and alter JSON's. I just thought it would be great if Geany could support this as well in a way that's practical for users, which would include the ability to fold and unfold arrays at different grains.

         
        • Lex Trotman

          Lex Trotman - 2014-11-27

          On 28 November 2014 at 01:29, arslaan beatboxa@users.sf.net wrote:

          Correct, but what I am asking for is support for JSON specifically, not
          Javascript in general (which already appears to work fine). So a JSON file
          should fold appropriately, since JSON is not 100% the same as Javascript.

          You need to add a lexer for Json to the editing component Scintilla
          which is a separate project (www.scintilla.org). Then it can be used
          in Geany.

          Cheers
          Lex

          Actually, I guess the ask would be 'folding on arrays in the condensed
          version of any markup language' if YAML also does not fold in condensed
          version.

          Today, I use a browser extension to browse and alter JSON's (including
          condensed version JSON with nested arrays). This extension can fold and
          unfold arrays and makes it very easy to explore and alter JSON's. I just
          thought it would be great if Geany could support this as well in a way
          that's practical for users, which would include the ability to fold and
          unfold arrays at different grains.


          [feature-requests:#745] Support for JSON

          Status: open
          Group: v1.25
          Labels: filetype json yaml filedefs
          Created: Sun Nov 23, 2014 06:15 PM UTC by arslaan
          Last Updated: Thu Nov 27, 2014 03:26 AM UTC
          Owner: nobody

          Feature request for support of JSON data (including condensed JSON). May be
          able to port quickly from YAML.

          Here is a valid condensed JSON record that does not appear to parse
          correctly in Geany 1.23.1 on Ubuntu 14.04:
          {"foo": "bar","baz": ["qux","quxx"],"corge": null,"grault":1,"garply":
          true,"waldo": "false","fred":"undefined","emptyArray": [],"emptyObject":
          {},"emptyString": ""}

          I've followed the wiki here (including the both the YAML lexer and the
          Javascript lexer):
          http://wiki.geany.org/config/json

          But this does not appear to parse JSON properly, particularly when
          condensed--possibly due to slightly different parsing between YAML and JSON.

          For the purposes of sample data for testing and comparing, these sites may
          be useful:
          http://jsontoyaml.com/
          http://yamltojson.com/

          Thanks in advance; and please let me know how I can contribute to this
          effort!


          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/geany/feature-requests/745/

          To unsubscribe from further messages, please visit
          https://sourceforge.net/auth/subscriptions/

           

          Related

          Feature Requests: #745

  • Colomban Wendling

    You need to add a lexer for Json to the editing component Scintilla
    which is a separate project (www.scintilla.org). Then it can be used
    in Geany.

    Or just add support for folding on [], this should be trivial to add to LexCPP. I didn't really checked what consequence it'd have but I doubt it's be a problem with another language it supports, can probably be interesting in other languages this lexer support that use [] as array literals, and can always be controlled by a lexer property if needed.

     
  • beatboxa

    beatboxa - 2014-11-29

    Gotcha...Thanks for the recommendations and for submitting the patch / patch request!

     

    Last edit: beatboxa 2014-11-29
  • Colomban Wendling

    • status: open --> closed-fixed
     
  • Colomban Wendling

    Implemented in 1.25

     

Log in to post a comment.