Recent

Author Topic: Read JSON names  (Read 1481 times)

korba812

  • Sr. Member
  • ****
  • Posts: 278
Re: Read JSON names
« Reply #15 on: May 24, 2022, 03:51:10 pm »
OpenAPI schema can be in YAML and JSON format. If you only have YAML schema then there are conversion tools to JSON.
Some time ago I made a simple OpenAPI client framework with an object generator. If you are interested I will create a repository on github.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 994
Re: Read JSON names
« Reply #16 on: May 24, 2022, 04:28:19 pm »
OpenAPI schema can be in YAML and JSON format. If you only have YAML schema then there are conversion tools to JSON.
Some time ago I made a simple OpenAPI client framework with an object generator. If you are interested I will create a repository on github.

Certainly!

korba812

  • Sr. Member
  • ****
  • Posts: 278
Re: Read JSON names
« Reply #17 on: May 24, 2022, 05:58:36 pm »
Here you have a repo:
https://github.com/michalgw/PasOAPI

A few remarks:
1. only supports a subset of OpenAPI types.
2. requires FPC trunk (uses custom attributes and extended rtti)
3. supports OpenAPI schema version 2 (or even earlier, I don't remember...), of course in JSON format
4. you need to implement your own "TPOConnector" class
5. "import" folder contains code generation tool


Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 891
  • Professional amateur ;-P
Re: Read JSON names
« Reply #18 on: May 25, 2022, 02:59:42 am »
Hey Korba,

Here you have a repo:
https://github.com/michalgw/PasOAPI

That's friggin' AWESOME!!!

Could I just trouble you to add content on the About section and probably drop a README.md file?

Apart from that, tremendous effort!!!

Many thanks for the share!!!

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.10 64b Dark Theme
http://github.com/gcarreno

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 994
Re: Read JSON names
« Reply #19 on: May 25, 2022, 11:45:54 am »
Here you have a repo:
https://github.com/michalgw/PasOAPI

A few remarks:
1. only supports a subset of OpenAPI types.
2. requires FPC trunk (uses custom attributes and extended rtti)
3. supports OpenAPI schema version 2 (or even earlier, I don't remember...), of course in JSON format
4. you need to implement your own "TPOConnector" class
5. "import" folder contains code generation tool

Thanks. It looks great, but unfortunately I cannot translate the YAML to JSON. I tried a few converters, three become unresponsive or do nothing, one gives an error: "Invalid YAML".

But I'm sure I'll have to attach more APIs in the future, so it will be useful when I come across one that uses JSON OpenAPI.

korba812

  • Sr. Member
  • ****
  • Posts: 278
Re: Read JSON names
« Reply #20 on: May 25, 2022, 01:44:40 pm »
Could I just trouble you to add content on the About section and probably drop a README.md file?
First I will try to refactor code and add OAPI v3 support. Then I will add examples and a short instruction. This project was developed as a "quick and dirty" solution, but since I have made it public, I feel obligated to improve the quality of this code.

Thanks. It looks great, but unfortunately I cannot translate the YAML to JSON. I tried a few converters, three become unresponsive or do nothing, one gives an error: "Invalid YAML".

But I'm sure I'll have to attach more APIs in the future, so it will be useful when I come across one that uses JSON OpenAPI.
Have you tried the Swagger Editor?
https://editor.swagger.io/
It is an OAPI schema editor and has ability to write schema to JSON.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 891
  • Professional amateur ;-P
Re: Read JSON names
« Reply #21 on: May 26, 2022, 09:43:31 am »
Hey Korba,

First I will try to refactor code and add OAPI v3 support. Then I will add examples and a short instruction. This project was developed as a "quick and dirty" solution, but since I have made it public, I feel obligated to improve the quality of this code.

That makes perfect sense and I'll be eager to follow such updates!!

Again, many thanks for making public this piece of good software!!

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.10 64b Dark Theme
http://github.com/gcarreno

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 994
Re: Read JSON names
« Reply #22 on: May 31, 2022, 08:41:51 am »
Have you tried the Swagger Editor?
https://editor.swagger.io/
It is an OAPI schema editor and has ability to write schema to JSON.

It took a few minutes, but it did manage to translate it. I'll come back to it.

sysrpl

  • Sr. Member
  • ****
  • Posts: 267
    • Get Lazarus
Re: Read JSON names
« Reply #23 on: June 03, 2022, 12:19:28 am »
If you were using JsonTools (https://github.com/sysrpl/JsonTools/) you can find nodes and their names using a variety of approaches. The full documentation on how to use it is on this page.

Code: Pascal  [Select][+][-]
  1. procedure JsonTest;
  2. const
  3.   JsonText = '{"SomeJSON": {"SomeName": "SomeValue", "AnObject": ' +
  4.     '{"AnotherName": 42, "AnArray": ["Bla", "Omg", "Zoef"]}}}';
  5. var
  6.   Root, Node: TJsonNode;
  7. begin
  8.   Root := TJsonNode.Create;
  9.   Root.Parse(JsonText);
  10.   for Node in Root do WriteLn(Node.Name);
  11.   for Node in Root.Child(0) do WriteLn(Node.Name);
  12.   for Node in Root.Find('SomeJSON/AnObject') do WriteLn(Node.Name);
  13.   Root.Free;
  14. end;

Outputs:
SomeJSON
SomeName
AnObject
AnotherName
AnArray
« Last Edit: June 03, 2022, 03:42:23 am by sysrpl »

 

TinyPortal © 2005-2018