Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Importing Json-formatted data from a .txt file into stata

    Dear Statausers,

    I am facing the following: I have received a .txt file containing data in json format. I would like to import such data into stata. As far as I understand, insheetjson and jsonio cannot help in this case, since they need the data to be in a .json file. Is there anything I can try?

    Happy to provide further clarifications and thanks in advance,
    Emanuele

  • #2
    So you have a file that is called something.txt, that contains data in json format, and you think that you can only import if it has a name like something.json. That should not be true. A json file is just a text file with some extra rules on what is in there.

    Have you tried it? Can you give us the exact command you used? What did Stata say? Can you give use one or two "observations" from your json/text file.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Dear Maarten,

      The data look like this (I've also attached a screenshot of the .txt):
      {"software_version": "NRZ-2020-129", "sensordatavalues":[{"value_type":"noise_Leq","value":"38.59"}], "timestamp":"2000-01-01T00:03:55Z"}, 15, SPH0645/t
      {"software_version": "NRZ-2020-129", "sensordatavalues":[{"value_type":"temperature","value":"23.50"},{"val ue_type":"humidity","value":"44.60"}], "timestamp":"2000-01-01T00:04:20Z"}, 7, DHT22/t
      {"software_version": "NRZ-2020-129", "sensordatavalues":[{"value_type":"lat","value":"-200.000000"},{"value_type":"lon","value":"-200.000000"},{"value_type":"height","value":"-1000.00"},{"value_type":"date","value":""},{"value _type":"time","value":""}], "timestamp":"2000-01-01T00:04:20Z"}, 9, GPS/t

      According to the STATA help, insheetjson only works with URLs, which I do not have.
      Hence, I tried jsonio's help (here: https://github.com/wbuchanan/StataJSON). Also in this case, I understand that the file should have a file with .json extension. For this reason (maybe I'm totally wrong), I changed the extension from .txt to .json. Then, I tried to apply the jsonio command:

      jsonio kv, file("C:\Users\wb562201\Downloads\936892_sensor_re adings.json") nourl ob(1) elem("(legs_[0-9]/((start)|(end))_location/((noise_Leq)|(temperature)))")

      to retrieve these variables: noise_Leq and temperature. I attach the error message that I got.
      Thanks

      Attached Files

      Comment

      Working...
      X