Code Monkey home page Code Monkey logo

neslib.json's Introduction

Neslib - Base library used by other Neslib projects

Neslib is a (still small) library of Delphi utilities that is shared across some other Neslib projects.

License

Neslib is licensed under the Simplified BSD License.

See License.txt for details.

neslib.json's People

Contributors

erikvanbilsen avatar neslib avatar vincentparrett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neslib.json's Issues

Neslib vs GrijjyFoundation

Looking for a json parser that fully support jsonpath - and there seems to be some similarity between neslib and GrijjyFoundation (same developers?) - so which should I chose? This one seems to have more recent commits (well to the json code anyway).

EAsertionFailed -> line 1280 Assert((UIntPtr(P) and TYPE_MASK) = 0);

Hi,

There is a problem Neslib.Json.pas on Linux, Android, and other platforms except Windows

The following lines will raise an Assertion Failed Error (line 1280 - Assert((UIntPtr(P) and TYPE_MASK) = 0); )

FJSONData:=TJsonDocument.CreateDictionary;
FJSONData.Root.AddOrSetValue('data','0'); <- will raise ASSERTION ERROR only if the VALUE IS one character long ON Android, Linux ... EXCEPT Windows

and in Neslib.Json

class function TJsonValue.Create(const AValue: JsonString): TJsonValue;
var
P: Pointer;
begin
P := nil;
JsonString(P) := AValue; // Increases ref count
Assert((UIntPtr(P) and TYPE_MASK) = 0); <- here
Result.FBits := TYPE_STR or UIntPtr(P);
end;

NOTE:

  1. I use delphi 10.4.2,
    http://docwiki.embarcadero.com/RADStudio/Sydney/en/Zero-based_strings_(Delphi)

(Workaround)
2. If I Typecast AValue to PChar the APP is working JsonString(P) := PChar(AValue); // Increases ref count
This change will impact the code in any other place?

Thank you,
Paul

Stringifying JSON array without indentation triggers error

program StringifyJsonArray;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils,
Neslib.Json {latest version};

var
doc: IJsonDocument;
u: utf8string;

begin
try
doc := TJsonDocument.Parse('{"i":[-1,0,1]}');
u := doc.ToJson(false); // works if parameter is changed to true; tested with Delphi 11.1 and Win64 as target
WriteLn(Utf8ToString(u));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReadLn;
end.

JPath unable to escape "."

Hi,

How can I escape "." in the front/ end of an element?

I have the following JSON:
{
"error_summary": "expired_access_token/",
"error": {
".tag": "expired_access_token"
}
}

I need to select ".tag" using JPath
using https://jsonpath.com/ I select the element with $.error.['.tag']
Using Neslib.Json I have the following error "Child operator in JSON path is missing a member name"

Thank you in advance,

UnitTest fails when decimal symbol is comma

My Windows is set to Icelandic regional settings and we use comma as a decimal separator.
Tried with decimal symbol as a dot and a comma and the test fails with a comma decimal separator
To Change The Format Goto: Control Panel -> Region -> Additional Settings -> Decimal Symbol

Tests Found : 187
Tests Ignored : 0
Tests Passed : 181
Tests Leaked : 0
Tests Failed : 6
Tests Errored : 0

Failing Tests

Tests.Neslib.Json.IO.TestJsonData.test_array_04
Message: Expected .=[]
.[0]=1
.[1]="abc"
.[2]=12.3
.[3]=-4 is not equal to actual .=[]
.[0]=1
.[1]="abc"
.[2]=12,3
.[3]=-4

Tests.Neslib.Json.IO.TestJsonData.test_basic_03
Message: Expected .=1.2345678 is not equal to actual .=1,2345678

Tests.Neslib.Json.IO.TestJsonData.test_real_04
Message: Expected .=1.2345678 is not equal to actual .=1,2345678

Tests.Neslib.Json.IO.TestJsonData.test_real_05
Message: Expected .=1234567.8 is not equal to actual .=1234567,8

Tests.Neslib.Json.IO.TestJsonData.test_real_06
Message: Expected .=-1.2345678 is not equal to actual .=-1,2345678

Tests.Neslib.Json.IO.TestJsonData.test_real_07
Message: Expected .=-1234567.8 is not equal to actual .=-1234567,8

Neslib.Utf8 - Compile error on Linux64: [Get|Reset|Set]MXCSR

Linux64:

[DCC Error] Neslib.Utf8.pas(1685): E2003 Undeclared identifier: 'GetMXCSR'
[DCC Error] Neslib.Utf8.pas(1687): E2003 Undeclared identifier: 'ResetMXCSR'
[DCC Error] Neslib.Utf8.pas(1783): E2003 Undeclared identifier: 'GetMXCSR'
[DCC Error] Neslib.Utf8.pas(1785): E2003 Undeclared identifier: 'SetMXCSR'

Windows64:

[dcc64 Warning] Neslib.Utf8.pas(1685): W1002 Symbol 'GetMXCSR' is specific to a platform
[dcc64 Warning] Neslib.Utf8.pas(1687): W1002 Symbol 'ResetMXCSR' is specific to a platform
[dcc64 Warning] Neslib.Utf8.pas(1783): W1002 Symbol 'GetMXCSR' is specific to a platform
[dcc64 Warning] Neslib.Utf8.pas(1785): W1002 Symbol 'SetMXCSR' is specific to a platform
[dcc64 Warning] Neslib.Utf8.pas(1853): W1002 Symbol 'SetMXCSR' is specific to a platform

JSON Path - Match error

Hi,
The following JPATH example $.book[10].author will raise error if the child 10 do not exists.
I think that will be better to only return an empty array (no match) or at least to have the ability to check if the path exists before execution.
There is any way to check if path exists?

Thanks,
Paul

Example needed

Example needed
Unclear how to get / iterate a dictionary
ex: JSONDoc.Root.Values['test'].IsDictionary= true
How to iterate this dictionary ... there is no method such as
for Key in Dictionary.Keys do

TJsonValue: array property defaults (suggestion)

Suggestion is to add these two (or similar) to TJsonValue...

    property Default[const AIndex: Integer]: TJsonValue read GetItem; default;
    property Default[const AName: JsonString]: TJsonValue read GetValue; default;

To enable this:

  const doc = TJsonDocument.Parse('{ "Numbers" : ["Zero", "One", "Two", "Three"]}');

  const old = doc.Root.Values['Numbers'].Items[2];
  const new = doc.Root['Numbers'][2];

Problem with stringifying a JSON string consisting of Chinese characters

The following code fails in a Delphi 11.1/Windows 64 Bit application with the conditional JSON_UTF8 defined in the Neslib.Json.* units:

program jsonwriter_err;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils, Neslib.Json;

var
doc: IJsonDocument;
s1, s2: utf8string;

begin
s1 := '{"s":"クランクケース/全面カバー"}';
doc := TJsonDocument.Parse(s1);
s2 := doc.Root.ToJson(false);
WriteLn(Utf8ToString(s2));
ReadLn;
end.

Call stack:

:00007FFD1609CD29 ; C:\WINDOWS\System32\KERNELBASE.dll
System._RaiseAtExcept(???,???)
System.SysUtils.AssertErrorHandler('Assertion fehlgeschlagen','... Neslib.Json.IO.pas',1586,$712F5D)
System._Assert(???,???,???)
Neslib.Json.IO.TJsonWriter.WriteEscapedString('クランクケース/全面カバー')
Neslib.Json.IO.TJsonWriter.WriteString('クランクケース/全面カバー')
Neslib.Json.TJsonValue.WriteTo(TJsonWriter($258AEED80A0) as IJsonWriter)
Neslib.Json.TJsonValue.TJsonDictionary.WriteTo(TJsonWriter($258AEED80A0) as IJsonWriter)
Neslib.Json.TJsonValue.WriteTo(TJsonWriter($258AEED80A0) as IJsonWriter)
Neslib.Json.TJsonValue.ToJson(False)

UTF8 encoding

I am not 100% certain to make the framework work with UTF8 content. I was under the impression that UTF8 would be used if the the string provided to parse is prepared correctly.
So I use this:

 LDoc := TJsonDocument.Parse( TEncoding.UTF8.GetString( ABytesArray ) );

Still, my content does not show unicode content correctly in a VCL app. So, I am wondering where I am not configuring it correctly.

Can't get a value as string nested more than three levels deep.

If I try and retrieve a value that is nested more than four or more level deep as a string, I get an exception, is this expected behavior?

example

{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95,
"Sale" : {
"OnSale" : "Yes"
}
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}

Retrieving $.store.book[0].Sale.OnSale as toJson works, however if I try asString it does not. toJson returns {
"OnSale" : "Yes"
}, though!

procedure TForm5.Button3Click(Sender: TObject);
var
Matches: TArray;
begin
JSONDoc:=TJsonDocument.Parse(memo1.Text);
matches:=TJsonPath.Match(JSONDoc,'$.'+edit1.Text);
label1.Caption:=matches[0].ToJson();
label1.Caption:=matches[0].ToString();
end;

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.