That's Confirmed The JSON foundation Bug SR-6631, is a Bug in Darwin's Objc Foundations.

Dear All,

Philippe Hausler has emitted the hypothesis that [SR-6631] Swift JSONEncoder is dependent to the locale decimal point policy encoding · Issue #4487 · apple/swift-corelibs-foundation · GitHub was a bug in Darwin Objc Foundations.
He was right! Shall i close the Swift SR-6631?

The following Objc Implementation is faulting:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv) {
    @autoreleasepool {
        // Let's set to french
        setlocale(LC_ALL,"fr_FR");
        NSDictionary *dictionary = @{@"decimalValue":@1.1};
        NSError* error = nil;
        NSData* data = [NSJSONSerialization dataWithJSONObject:dictionary options:kNilOptions error:&error];
        NSString * json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"%@",json);
    }
    return 0;
}

Result : 2017-12-19 09:08:49.657316+0100 doubleEncodingObjc[2016:82301] {"decimalValue":1,1000000000000001}

I’have been updating the relevant radar: Feedback Assistant

Benoit

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/&gt;

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

Hi Benoit,

Thanks for the bug report. We’ll track it in Radar for Darwin platforms.

If the swift-corelibs-foundation implementation has the same bug (perhaps — I haven’t checked) then we can continue to track it with SR-6631 separately.

- Tony

···

On Dec 19, 2017, at 12:23 AM, Benoit Pereira da silva via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Dear All,

Philippe Hausler has emitted the hypothesis that [SR-6631] Swift JSONEncoder is dependent to the locale decimal point policy encoding · Issue #4487 · apple/swift-corelibs-foundation · GitHub was a bug in Darwin Objc Foundations.
He was right! Shall i close the Swift SR-6631?

The following Objc Implementation is faulting:

import <Foundation/Foundation.h>

int main(int argc, const char * argv) {
    @autoreleasepool {
        // Let's set to french
        setlocale(LC_ALL,"fr_FR");
        NSDictionary *dictionary = @{@"decimalValue":@1.1};
        NSError* error = nil;
        NSData* data = [NSJSONSerialization dataWithJSONObject:dictionary options:kNilOptions error:&error];
        NSString * json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"%@",json);
    }
    return 0;
}

Result : 2017-12-19 09:08:49.657316+0100 doubleEncodingObjc[2016:82301] {"decimalValue":1,1000000000000001}

I’have been updating the relevant radar: Feedback Assistant <Feedback Assistant;

Benoit

Benoit Pereira da Silva
Ultra Mobile Developer & Movement Activist
Développeur Ultra Mobile & Militant du mouvement
https://pereira-da-silva.com <https://pereira-da-silva.com/&gt;

<bannerp.jpg>

✄ --------------------------------
This e-mail is confidential. Distribution, copy, publication or use of this information for any purpose is prohibited without agreement of the sender.
Ce message est confidentiel. Toute distribution, copie, publication ou usage des informations contenues dans ce message sont interdits sans agrément préalable de l'expéditeur.

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

I've just encountered this bug. It seems to continue existing on macOS Mojave 10.14.2 which is surprising given that is a serious bug, you cannot encode valid JSON with decimal values in a lot of locales. Any update?