Recent

Author Topic: how to validate json structure  (Read 401 times)

Packs

  • Sr. Member
  • ****
  • Posts: 364
how to validate json structure
« on: October 08, 2024, 12:03:06 pm »
how to validate json structure in lazarus

Thaddy

  • Hero Member
  • *****
  • Posts: 16138
  • Censorship about opinions does not belong here.
Re: how to validate json structure
« Reply #1 on: October 08, 2024, 12:09:34 pm »
Use the fcl-json package. There are many examples on the forum just search for it.
https://wiki.freepascal.org/fcl-json#:~:text=fcl-json%20contains%20the%20unit%20%22fpjsonrtti%22%20which%20is%20used
If I smell bad code it usually is bad code and that includes my own code.

Packs

  • Sr. Member
  • ****
  • Posts: 364
Re: how to validate json structure
« Reply #2 on: October 08, 2024, 02:13:35 pm »
I know this.

I want json validator library which will help

If some post json data through api.

It should validate structure and type then it should call

The api.

Warfley

  • Hero Member
  • *****
  • Posts: 1734
Re: how to validate json structure
« Reply #3 on: October 08, 2024, 02:24:44 pm »
What do you mean by validate? Syntactic validation? Simple try to parse it and if it doesn't throw an error it's correct. Or schema validation? For the latter take a look at this: https://forum.lazarus.freepascal.org/index.php?topic=62844.0

Packs

  • Sr. Member
  • ****
  • Posts: 364
Re: how to validate json structure
« Reply #4 on: October 08, 2024, 04:41:09 pm »
Api structure validation means

Example my api take 4 input

When user send request. It should have 4 input as well as it's key and data type should match

It should validate .

Ștefan-Iulian Alecu

  • New Member
  • *
  • Posts: 21
Re: how to validate json structure
« Reply #5 on: October 08, 2024, 09:47:08 pm »
Api structure validation means

Example my api take 4 input

When user send request. It should have 4 input as well as it's key and data type should match

It should validate .

Then validate its schema, look at the link Warfley sent.
https://json-schema.org/learn

silvercoder70

  • Jr. Member
  • **
  • Posts: 88
    • Tim Coates
Explore the beauty of modern Pascal programming with Delphi & Free Pascal - https://www.youtube.com/@silvercoder70

 

TinyPortal © 2005-2018