Discussion:
JSON for Visual FoxPro
Paul Newton
2018-11-16 11:49:34 UTC
Permalink
Hi all

This is on Craig Boyd's Sweet Potato Software site (https://tinyurl.com/ybk97s97) but the download link is coming up 404. Any ideas where I can get hold of it?
Or alternative VFP options to handle JSON? I have tried the following from various sources (e.g. VFPX, GitHub, CodePlex) :
nfJson-master (Marco Plaza), vfpJson-master (Ignacio Gutiérrez Torrero), qdfoxjson (Victor Espina)

but none of them can decode JSON strings like this:

"{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}"

They all appear to stumble because of the additional JSON between the [] brackets. I could StrExtract the string between the [] and decode that separately but I would rather find something that can handle this directly. Failing that I'll have to "roll my own".

Thanks

Paul Newton

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@SN6PR02MB5552.namprd02.prod.outlook.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Thierry Nivelet
2018-11-16 12:29:07 UTC
Permalink
FoxInCloud has a FOSS function doing that, provided you remove the ‘\’ escape characters:

o = uValueJS(Strtran('{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}', '\"', '"'))

https://github.com/FoxInCloud/FoxInCloud-AB <https://github.com/FoxInCloud/FoxInCloud-AB>

Thierry Nivelet
FoxinCloud
Give your VFP app a new life in the cloud
http://foxincloud.com/
Post by Paul Newton
Hi all
This is on Craig Boyd's Sweet Potato Software site (https://tinyurl.com/ybk97s97) but the download link is coming up 404. Any ideas where I can get hold of it?
nfJson-master (Marco Plaza), vfpJson-master (Ignacio Gutiérrez Torrero), qdfoxjson (Victor Espina)
"{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}"
They all appear to stumble because of the additional JSON between the [] brackets. I could StrExtract the string between the [] and decode that separately but I would rather find something that can handle this directly. Failing that I'll have to "roll my own".
Thanks
Paul Newton
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/02DD95F0-95DF-4B04-8705-***@foxincloud.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those l
Thierry Nivelet
2018-11-16 12:33:25 UTC
Permalink
oops, sorry, it’s in the Web layer, not in the public layer

if you’re stuck and no dependency to the Web layer, I can move it to the public layer AB

just let me know

Thierry Nivelet
Post by Thierry Nivelet
o = uValueJS(Strtran('{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}', '\"', '"'))
https://github.com/FoxInCloud/FoxInCloud-AB <https://github.com/FoxInCloud/FoxInCloud-AB> <https://github.com/FoxInCloud/FoxInCloud-AB <https://github.com/FoxInCloud/FoxInCloud-AB>>
Thierry Nivelet
FoxinCloud
Give your VFP app a new life in the cloud
http://foxincloud.com/ <http://foxincloud.com/>
Post by Paul Newton
Hi all
This is on Craig Boyd's Sweet Potato Software site (https://tinyurl.com/ybk97s97) but the download link is coming up 404. Any ideas where I can get hold of it?
nfJson-master (Marco Plaza), vfpJson-master (Ignacio Gutiérrez Torrero), qdfoxjson (Victor Espina)
"{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}"
They all appear to stumble because of the additional JSON between the [] brackets. I could StrExtract the string between the [] and decode that separately but I would rather find something that can handle this directly. Failing that I'll have to "roll my own".
Thanks
Paul Newton
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/3C969C5C-E019-4754-BFFC-***@foxincloud.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid
Paul Newton
2018-11-16 12:37:52 UTC
Permalink
Thanks Thierry - I'll look into it

-----Original Message-----
From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Thierry Nivelet
Sent: 16 November 2018 12:29
To: ***@leafe.com
Subject: Re: JSON for Visual FoxPro

Sent by an external sender
------------------------------

FoxInCloud has a FOSS function doing that, provided you remove the ‘\’ escape characters:

o = uValueJS(Strtran('{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}', '\"', '"'))

https://github.com/FoxInCloud/FoxInCloud-AB <https://github.com/FoxInCloud/FoxInCloud-AB>

Thierry Nivelet
FoxinCloud
Give your VFP app a new life in the cloud http://foxincloud.com/
Post by Paul Newton
Hi all
This is on Craig Boyd's Sweet Potato Software site (https://tinyurl.com/ybk97s97) but the download link is coming up 404. Any ideas where I can get hold of it?
nfJson-master (Marco Plaza), vfpJson-master (Ignacio Gutiérrez
Torrero), qdfoxjson (Victor Espina)
"{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}"
They all appear to stumble because of the additional JSON between the [] brackets. I could StrExtract the string between the [] and decode that separately but I would rather find something that can handle this directly. Failing that I'll have to "roll my own".
Thanks
Paul Newton
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/02DD95F0-95DF-4B04-8705-***@foxincloud.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Report [OT] Abuse: http://leafe.com/reportAbuse/02DD95F0-95DF-4B04-8705-***@foxincloud.com
_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@SN6PR02MB5552.namprd02.prod.outlook.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see t
Alan Bourke
2018-11-16 12:32:32 UTC
Permalink
nfjson seems okay with it if you strip out the escaping on the double quotes.

x = '{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}'
y=chrtran(x,"\","")
oJson = nfJsonRead(y)
--
Alan Bourke
alanpbourke (at) fastmail (dot) fm

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@webmail.messagingengine.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Paul Newton
2018-11-16 12:39:11 UTC
Permalink
Thanks Alan - I'll try that on some real JSON I am working with

-----Original Message-----
From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Alan Bourke
Sent: 16 November 2018 12:33
To: ***@leafe.com
Subject: Re: JSON for Visual FoxPro

Sent by an external sender
------------------------------

nfjson seems okay with it if you strip out the escaping on the double quotes.

x = '{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}'
y=chrtran(x,"\","")
oJson = nfJsonRead(y)
--
Alan Bourke
alanpbourke (at) fastmail (dot) fm

[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@SN6PR02MB5552.namprd02.prod.outlook.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Alan Bourke
2018-11-16 13:44:36 UTC
Permalink
TBF I don't think all those double quotes should be escaped anyway. IIRC it's only if you're including string data and the string data has double quotes in it.

{
"string1":"This value legitimately contains \"some quotes\""}
}
--
Alan Bourke
alanpbourke (at) fastmail (dot) fm

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@webmail.messagingengine.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Paul Newton
2018-11-16 13:56:25 UTC
Permalink
Alan

The problem occurred when I was working in .NET - hence the need for escaping the double quotes

Paul
-----Original Message-----
From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Alan Bourke
Sent: 16 November 2018 13:45
To: ***@leafe.com
Subject: Re: JSON for Visual FoxPro

Sent by an external sender
------------------------------

TBF I don't think all those double quotes should be escaped anyway. IIRC it's only if you're including string data and the string data has double quotes in it.

{
"string1":"This value legitimately contains \"some quotes\""} }



--
Alan Bourke
alanpbourke (at) fastmail (dot) fm

[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@SN6PR02MB5552.namprd02.prod.outlook.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Tracy Pearson
2018-11-16 15:13:06 UTC
Permalink
This post might be inappropriate. Click to display it.
José Enrique Llopis
2018-11-16 12:42:39 UTC
Permalink
That function decodes unicode entities in case it can be of help
-----------------------------------------------------------------


FUNCTION _FFWK_DecodeUnicodeEntities
LPARAMETERS tcString

LOCAL lcResultString, lnPosicion, lcChar, lcTokenString

m.lcResultString = m.tcString

DO WHILE .T.
m.lnPosicion = AT( "\u", m.lcResultString, 1 )
IF m.lnPosicion = 0
EXIT
ENDIF
m.lcTokenString = SUBSTR( m.lcResultString, m.lnPosicion, 6 )

IF LOWER(m.lcTokenString) = "\u20ac"
m.lcChar = "€"
ELSE
TRY
m.lcChar = CHR( EVALUATE( "0x" + SUBSTR( m.lcResultString, m.lnPosicion + 2, 4) ) )
CATCH
m.lcChar = ""
ENDTRY
ENDIF

m.lcResultString = STRTRAN( m.lcResultString , m.lcTokenString, m.lcChar )

ENDDO

RETURN m.lcResultString

ENDFUNC



------------------------------------
Jose Enrique Llopis
------------------------------------




-----Mensaje original-----
De: ProFox [mailto:profox-***@leafe.com] En nombre de Paul Newton
Enviado el: viernes, 16 de noviembre de 2018 12:50
Para: '***@leafe.com'
Asunto: JSON for Visual FoxPro

Hi all

This is on Craig Boyd's Sweet Potato Software site (https://tinyurl.com/ybk97s97) but the download link is coming up 404. Any ideas where I can get hold of it?
Or alternative VFP options to handle JSON? I have tried the following from various sources (e.g. VFPX, GitHub, CodePlex) :
nfJson-master (Marco Plaza), vfpJson-master (Ignacio Gutiérrez Torrero), qdfoxjson (Victor Espina)

but none of them can decode JSON strings like this:

"{\"code\":\" ERROR\",\"message\":\"Message \",\"errors\":[{\"field1\":\"FIELD\",\"value\":\"VALUE\"}]}"

They all appear to stumble because of the additional JSON between the [] brackets. I could StrExtract the string between the [] and decode that separately but I would rather find something that can handle this directly. Failing that I'll have to "roll my own".

Thanks

Paul Newton

[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@LENOVO1
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too s
Loading...