Coder Social home page Coder Social logo

expandjson's Introduction

expandJSON v1.12 (w/ experimental array decoding)

    Expand a JSON string from a reading into individual readings

    • Requirement: perl module JSON
      Use "cpan install JSON" or operating system's package manager to install Perl JSON Modul. Depending on your os the required package is named: libjson-perl or perl-JSON.

    Define

      define <name> expandJSON <source_regex> [<target_regex>]

      <li>
        <b>&lt;name&gt;</b><br>
        A name of your choice.</li><br>
      
      <li>
        <b>&lt;source_regex&gt;</b><br>
        Regexp that must match your devices, readings and values that contain
        the JSON strings. Regexp syntax is the same as used by notify and must not
        contain a space.<br>
        </li><br>
        
      <li>
        <b>&lt;target_regex&gt;</b><br>
        Optional: This regexp is used to determine whether the target reading is
        converted or not at all. If not set then all readings will be used. If set
        then only matching readings will be used. Regexp syntax is the same as
        used by notify and must not contain a space.<br>
        </li><br>
      
      <li>
        Examples:<br>
        <br>
        <u>Source reading:</u><br>
          <code>device:reading:.{.*}</code><br>
          <code>.*WifiIOT.*:sensor.*:.{.*}</code><br>
          <code>sonoff_.*:.*:.{.*}</code><br>
          <code>dev.*:(sensor1|sensor2|teleme.*):.{.*}</code><br>
          <code>(dev.*|[Dd]evice.*):json:.{.*}</code><br>
          <code>(devX:jsonX:.{.*}|devY.*:jsonY:.{.*Wifi.*{.*SSID.*}.*})</code><br>
        <br>
      
        <u>Target reading:</u><br>
          <code>.*power.*</code><br>
          <code>(Current|Voltage|Wifi.*)</code><br>
        <br>
      
        <u>Complete definitions:</u><br>
          <code>define ej1 expandJSON device:sourceReading:.{.*} targetReading</code><br>
          <code>define ej3 expandJSON .*\.SEN\..*:.*:.{.*}</code><br>
          <code>define ej3 expandJSON sonoff_.*:sensor.*:.{.*} (power.*|current|voltage)</code><br>
        <br>
      </li><br>
      

    Set

      N/A

    Get

      N/A

    Attributes

    • addReadingsPrefix
      Add source reading as prefix to new generated readings. Useful if you have more than one reading with a JSON string that should be converted.

    • <li><b>disable</b><br>
        Used to disable this device.
      </li><br>
      
      <li><b>do_not_notify</b><br>
        Do not generate events for converted readings at all. Think twice before
        using this attribute. In most cases, it is more appropriate to use 
        event-on-change-reading in target devices.
      </li><br>
      
      <li><b>disabledForIntervals</b></li>
      <li><b>addStateEvent</b></li>
      

expandjson's People

Contributors

ddtlabs avatar

Stargazers

 avatar

Watchers

 avatar  avatar

expandjson's Issues

Treatment of special characters

Special characters like German Umlauts (ä, ö, ü) are not properly decoded to Perl strings. Example:
the JSON string { "demo-string":"aäoöuü" } is translated into reading demo-string with valuea�o�u�. This happens because the used function json_decode applies a UTF-8 decode on the input string although Perl strings are already decoded.

Support for boolean values

The module doesn't create readings for boolean values. For example:
{ "timestamp":1496588366, "sensor_id":"5157", "temperature":23.8, "humidity":59, "lowbat":true, "rssi":79 }
The module creates readings for all values but lowbat. I suppose this is because boolean values have no surrounding quotes in JSON and perl doesn't have a boolean type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.