Neslib is a (still small) library of Delphi utilities that is shared across some other Neslib projects.
Neslib is licensed under the Simplified BSD License.
See License.txt for details.
Fast and memory-efficient JSON for Delphi
License: Other
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).
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); )
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:
(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
Delphi 11.1 is reporting this :
[dcc32 Hint] Neslib.Json.Path.pas(847): H2443 Inline function 'TJsonValue.TryGetValue' has not been expanded because unit 'System.Classes' is not specified in USES list
I will submit a PR.
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.
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,
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
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
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
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
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];
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)
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.
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;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.