Menu

Json, avoid type conversion

Help
Anonymous
2022-06-12
2022-06-13
  • Anonymous

    Anonymous - 2022-06-12

    echo { "bitrate":1603000 } | xidel.exe - --silent --extract
    "($json).bitrate

    gives

    1.603E6
    

    ... how can I avoid conversion to obtain '1603000'

    Thx in advance

     
  • Reino

    Reino - 2022-06-13

    XPath notation:

    ECHO {"bitrate":1603000} | xidel -se "$json/decimal(bitrate)"
    ECHO {"bitrate":1603000} | xidel -se "$json/integer(bitrate)"
    ECHO {"bitrate":1603000} | xidel -se "$json/int(bitrate)"
    ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as decimal"
    ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as integer"
    ECHO {"bitrate":1603000} | xidel -se "$json/bitrate cast as int"
    

    dot notation, what you're using:

    ECHO {"bitrate":1603000} | xidel -se "($json).bitrate cast as decimal"
    ECHO {"bitrate":1603000} | xidel -se "($json).bitrate cast as integer"
    ECHO {"bitrate":1603000} | xidel -se "($json).bitrate cast as int"
    ECHO {"bitrate":1603000} | xidel -se "decimal(($json).bitrate)"
    ECHO {"bitrate":1603000} | xidel -se "integer(($json).bitrate)"
    ECHO {"bitrate":1603000} | xidel -se "int(($json).bitrate)"
    

    When you use the functions (decimal(), etc.) in this case, then you have to enclose the entire query. ($json).decimal(bitrate) won't work.

    Btw, if you're using one of the latest development builds, then the - (dash for stdin) isn't necessary anymore.

    Also see:
    - https://sourceforge.net/p/videlibri/mailman/videlibri-xidel/thread/db8bdc2e-4a17-3640-f040-fc958bc75498%40xs4all.nl/#msg37179400
    - https://github.com/qt4cg/qtspecs/issues/33

     

    Last edit: Reino 2022-06-13
  • Anonymous

    Anonymous - 2022-06-13

    VERIFIED
    thx

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.