omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Storing text from textview as JSON String

    Pythonista
    2
    3
    2365
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ramvee
      ramvee last edited by

      Hi Friends,
      I just want to take input from TextView Or Any Text Clip And Store It In As A JSON String, including newlines and tabs. Lot of scripts teach how to strip escape characters, i want the program to insert them automatically.

      It is taking me a lot of time to insert \n and \t manually.
      I ultimately want to store a bunch recipes in JSON file, as simple dictionary.
      Thank you. Ram

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        json.dump can be used to write a list or dict into a JSON file, and json.load to read a JSON file. The json library automatically escapes and unespaces all strings when writing/reading, that way you don't need to do any of that by hand.

        1 Reply Last reply Reply Quote 0
        • ramvee
          ramvee last edited by

          Thank You @dgelessus ,
          I have been sitting and editing JSON data files manually, inserting \n \b..
          :)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors