Recent

Author Topic: [SOLVED] jsonparser - Cannot convert data from Null value  (Read 4114 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
[SOLVED] jsonparser - Cannot convert data from Null value
« on: December 06, 2017, 05:08:15 pm »
hi All,
please advise if for the jsonparser from standard library there is an option to ignore null values.
rfc 4627 allows null but indeed the easiest to say is just for a string conversion to ''.
i see that the approach for null values for other de-serealizers is to have an ignore option.
my JSON is as below:

Code: Pascal  [Select][+][-]
  1. {"away":false,"organisation":"xxx","host":"xxx","loggedIn":true,"user":"xxx","idleTime":163,"qubicle":"xxx","name":null,"version":"xxx","windowState":"hidden"}

thank you
« Last Edit: December 07, 2017, 08:58:46 am by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: jsonparser - Cannot convert data from Null value
« Reply #1 on: December 06, 2017, 08:50:26 pm »
There's none as far as the source code is concerned. Still, I don't understand why you need such a functionality while IsNull method is provided for every node.

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: jsonparser - Cannot convert data from Null value
« Reply #2 on: December 07, 2017, 08:58:09 am »
thank you
i was not aware of the isNull check.

Code: Pascal  [Select][+][-]
  1. if not jsData.FindPath('user').IsNull then
  2.               _Model.TheStatus.UserCode := jsData.FindPath('user').AsString;

the above works and will work with it.
nevertheless i feel that an ignore option is more productive than having isNull check at field level.
Lazarus 2.0.2 64b on Debian LXDE 10

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: jsonparser - Cannot convert data from Null value
« Reply #3 on: December 07, 2017, 09:05:50 am »
nevertheless i feel that an ignore option is more productive than having isNull check at field level.
errr...... No. You can't ignore it if you do not know its null so the field level check will always run.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: [SOLVED] jsonparser - Cannot convert data from Null value
« Reply #4 on: December 07, 2017, 09:31:46 am »
by productive i meant for the programmer to just set an option. there is only an option to set when defining the parser and not x fields to update with the isNull condition check.
less lines of code to write - faster delivery.

(i was not referring to the performance angle where the check would need to run for each field due to the option.)
Lazarus 2.0.2 64b on Debian LXDE 10

 

TinyPortal © 2005-2018